I have two linked combo, Year and Week.
Im sending the list of year and empty data set for week to the View
ViewBag.YearID = new SelectList(db.years, "YearID", "Name");
ViewBag.WeekID = new SelectList(db.week_list.Where(x => x.Name == ""), "WeekID", "Name");
In the View I have
@Html.DropDownList("YearID", null, "Seleccione Año", htmlAttributes: new { @class = "form-control" })
@Html.DropDownList("WeekID", null, htmlAttributes: new { @class = "form-control" })
Right now when start Year have a help message Select Year
without value.
<select class="form-control" id="YearID" name="YearID">
<option value="">Seleccione Año</option>
<option value="7">2016</option>
<option value="8">2017</option>
<option value="9">2018</option>
</select>
So because not year has been selected I pass an empty list for weeks and result on this:
<select class="form-control" id="WeekID" name="WeekID">
</select>
Starting State:
The problem is when I hit Create
button to send the form. The action controller get the wrong value for WeekID
YearID = null -- as I espect
WeekID = 0 -- dont know why. I expect null
Then the validation show Year is required, but doesnt show anything for Week because already received 0
Validation State: