I am very new to MVC 3, so this can be easy. I have a viewmodel with a nested object like this:
public class EventViewModel
{
public Event Event { get; set; }
}
public class Event
{
[Required]
public int Id { get; set; }
public string Title { get; set; }
}
In my "create" view, I am doing something like this:
@model EventViewModel
@Html.EditorFor(model => model.Event.Title)
Here the code forms my event controller:
public class EventController : Controller
{
[HttpPost]
public ActionResult Create(EventViewModel @event)
{
...
}
}
This editor is inside the form tag. When I get back to my controller, the title of the event will be null, not what I entered into the form. Do I need some kind of individual binder? Am I doing something unconventional when I use nested objects in my view model?
source
share