locked
Problems with validation code RRS feed

  • Question

  • User1457412228 posted
    @section scripts {
        @await Html.PartialAsync("_ValidationScriptsPartial")
        <script type="text/javascript">
    
         

    (Google only shows about 500 total listings for @await Html.PartialA... so not a lot of people asking about this apparently.)  

    I am new to dot net core and razor pages.

    Supposedly the above is required, in addition to the regular validation code, but when I run it, it does not show any messages.  Could this be because the form is in a modal <div>?

    Here is the form that is supposed to be validated.  It does keep the form from being submitted, unless all the required values are there, but there are no error messages.  

    here is the form that is supposed to be validated with error messages.  IT stops submission and moves the cursor to one of the entries that is missing, but does not display any error messages.

     <form id="modalFormEducation" method="post" class="col-sm-12">
                    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                    @*<form id="modalFormEducation" method="post" class="col-sm-12" data-ajax="true" data-ajax-method="post" data-ajax-complete="completed">*@
                    <div class="modal-header">
                        <h5 class="modal-title text-center text-info" id="exampleModalLabel">SCHOOL</h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <input hidden id="id" class="col form-control formMargin" type="text" asp-for="@Model.School.ID">
                        <div class="form-row" style="margin-bottom:5px;">
    
                            <input id="idFieldOfStudy" class="col form-control formMargin" type="text" asp-for="@Model.School.FieldOfStudy" placeholder="FIELD OF STUDY">
    
                            <div asp-validation-for="School.FieldOfStudy" class="text-danger"></div>
                        </div>
                        <div class="form-row" style="margin-bottom:5px;">
    
                            <input id="idSchoolName" class="col form-control formMargin" type="text" asp-for="@Model.School.SchoolName" placeholder="SCHOOL NAME" />
                            <div asp-validation-for="School.SchoolName" class="text-danger"></div>
                        </div>

    and here is a partial snippet from the class.

     public partial class Education
        {
            public long ID { get; set; }
            public long UsersID { get; set; }
    
            [Required(ErrorMessage = "Field Is Required")]
            [StringLength(60, MinimumLength = 3)]
            public string SchoolName { get; set; }
    
            [Required(ErrorMessage = "Field Is Required")]        
            [StringLength(60, MinimumLength = 3)]
            public string SchoolCity { get; set; }
    
            [Required(ErrorMessage = "Field Is Required")]
            [StringLength(2)]
            public string SchoolState { get; set; }

    I don't have labels for the inputs because I think it looks better in a modal to have the placeholder tell people what the required value is for.

    I am using core 2.2

     

    My question again is, "Why don't any error messages show up?"

    Saturday, July 13, 2019 7:10 PM

Answers

All replies