Open Closed

why client validation not working in web public project mvc core razor ? #9450


User avatar
0
devmahmod created

why client validation not working in web public project mvc core razor


7 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team AI Bot
    • To enable client-side validation in an ABP MVC Core Razor Pages project, you must ensure that the required validation scripts are included in your layout. ABP's default layouts include these scripts, but if you use a custom layout, you need to add them manually.

    • Add the following lines before the closing </body> tag in your custom layout to enable client-side validation:

    @section Scripts
    {
        <partial name="_ValidationScriptsPartial" />
    }
    

    Or, if your layout does not support sections, add directly:

    <partial name="_ValidationScriptsPartial" />
    
    • Make sure your form includes the correct asp-validation-summary and asp-validation-for tags, which you already have.

    • Also, ensure that jQuery and the validation libraries are loaded. The _ValidationScriptsPartial partial includes these by default.

    • If you use a custom error message key (e.g., "Validation:EmailRequired"), ensure that your localization resources contain the corresponding translations.

    • Example minimal layout addition:

    <body>
        @RenderBody()
        <partial name="_ValidationScriptsPartial" />
    </body>
    
    • After these changes, client-side validation should work as expected for your form.

    Sources:

    • https://abp.io/docs/latest/framework/ui/mvc-razor-pages/forms-validation

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    devmahmod created

    thanks but it is give me error InvalidOperationException: The partial view '_ValidationScriptsPartial' was not found. The following locations were searched: /Pages/_ValidationScriptsPartial.ar.cshtml /Pages/_ValidationScriptsPartial.cshtml /Pages/Shared/_ValidationScriptsPartial.ar.cshtml /Pages/Shared/_ValidationScriptsPartial.cshtml /Views/Shared/_ValidationScriptsPartial.ar.cshtml /Views/Shared/_ValidationScriptsPartial.cshtml

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    why client validation not working in web public project mvc core razor

    Can you explain it in detail? share some screenshots.

    Thanks.

  • User Avatar
    0
    devmahmod created

    I solved it by making this I moved @RenderSection("scripts", required: false) from header tag to be before closed body tag and also add <!-- ✅ jQuery Validation and Unobtrusive --> <script src="~/libs/jquery-validation/jquery.validate.js"></script> <script src="~/libs/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script> and also make inputs like this

    <div class="form-group form-group__container"> <label for="Name" class="control-label"> <span class="text-danger">*</span> @L["Name"] </label> @Html.TextBoxFor(m => m.Name, new { @class = "form-control", placeholder = @L["NamePlaceholder"] }) @Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" }) </div>

    Thanks

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Great 👍

  • User Avatar
    0
    devmahmod created

    [maliming] said: Great 👍

    thanks for your response and support

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on June 13, 2025, 11:37