[RESOLVED]Something is triggering unobtrusive validation, but what?

I have a fairly simple mvc form with validation.  One of the sections is a dynamically added partial view (add a new row with a button click).  Something in there is triggering a validation error, but I can’t find it.  It is requiring the IdentificationType
dropdown have a selected value, but as far as I can see, there is no "Required" set anywhere in the code.  There are 4 different sections setup as dynamiclly added partials and they are all fine.  The only difference I can see is the id type is a dropdown,
and it is the only one triggering the validation error.  Is this a dropdown thing?  Here is some code:

Partial view:

        <div class="IdentPartial" > 
             <div class="formGroup-Short">
                <div class="editor-label">
                    @*@Html.HiddenFor(m => m.IdentificationCounter, new { @class="iHidden" })*@
                    @Html.Label("Identification Type")
                </div>
                <div class="editor-field">
                     @Html.DropDownListFor(m => m.IdentificationModel[Model.IdentificationCounter].IdentificationType, new SelectList(Model.IDTypes, "Value", "Text"), "Select", new { style = "width: 150px;" })
                </div>
            </div>
        
            <div class="formGroup-Short">
                <div class="editor-label">
                    @Html.Label("Identification Number")
                </div>
                <div class="editor-field">
                    @Html.TextBoxFor(m => m.IdentificationModel[Model.IdentificationCounter].IdentificationNumber, new { style = "width:120px" })
                </div>
            </div>

            <div class="formGroup">
                <div class="editor-label"  style="width: 100px">
                    @Html.Label("Issuing State")
                </div>
                <div class="editor-field">
                    @Html.DropDownListFor(m => m.IdentificationModel[Model.IdentificationCounter].IssuingState, new SelectList(Model.State, "Value", "Text", "OR"), "Select", new { style = "width: 65px; margin-right:20px;" })
                </div>
            </div>
        </div>

ID Model:

    public class IdentificationMetadata
    {

        [DisplayName("Identification Type")]
        public string IdentificationType { get; set; }

        [DisplayName("Identification Number")]
        public string IdentificationNumber { get; set; }
        
        [DisplayName("State")]
        public string IssuingState { get; set; }
    }

jQuery script, button event:

            $("#AddId").on("click", function () {
                var itemIndex = $(".IdentPartial .iHidden").length;
                $.get(
                    "@Url.Action("NewIdentRow")/" + itemIndex,
                    function (data) {
                        $("#IdentDataSection").append(data);
                    });
            });

Can you send the exact error message you are getting it?

As far as i see you don’t have a required field in your model.

I finally found the solution, the IdentificationType was a not null int in the DB.  I made it nullable in the DB and changed it int he model, now if doesnt trigger the validation.

Leave a Reply