I have a very simple model. I have a location that has 2 fields, Id and Name. I have InventoryItems that has a number of scalar fields with a FK to the location at which it is stored. I have a View for creating an InventoryItem. The view has a drop down for `
<div class="editor-label">
@Html.LabelFor(model => model.Location)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.Location.Id, new SelectList(ViewBag.Locations, "Id", "Name"))
</div>
The controller code checks ModelState.IsValid which is returning false because the NAME of the location in the ModelState is empty. I really only need the Id to save the InventoryItem. But I have [required] in the Location Name field because when I go to allowing the addition of Locations, I want that field required.
Can someone tell me the CORRECT way to deal with this in the MVC design pattern?