I have a property in my model very simple one:

Now this dropDown doesn’t work right
@Html.DropDownListFor(m => m.Camp, new SelectList(ViewBag.Camps, "Id", "Name"))
it returns null instead of a chosen Camp, but if I change that into:
@Html.DropDownListFor(m => m.Camp.Id, new SelectList(ViewBag.Camps, "Id", "Name"))
It would return me a Camp object with correct Id, but the Name would be still null.
Why?
UPD:
And now another problem is if I choose the second approach it would screw up with unobtrusive validation. Although I’ll be able to get the right camp based on the chosen id.
That’s normal. Only the
Idis posted to the controller action. That’s how dropdown inside forms work. So that’s all you can hope to get there. You will then use thisIdto get the corresponding Camp object from the database:Also please get rid of this
ViewBagand use a real view model:and in the controller:
and the view: