I have a ASP.NET MVC wrapper class that wraps a List containing ViewModels:
public class ScheduleContainerViewModel
{
public List<SchedulingViewModel> Items { get; set; }
public ScheduleContainerViewModel(List<SchedulingViewModel> items)
{
Items = items;
}
SchedulingViewModel
contains a Schedule
object and a Users
object.
ScheduleContainerViewModel
is eventually passed to a PartialView
.
This PartialView
is called via Ajax to populate a div in a View
. The model for the PartialView
is ScheduleContainerViewModel
and the model for the View
is a Job
.
The Ajax GET works great. When I try to POST
it, however, the Controller is never called and I get a 500 server error. Here's some of the XHR data being POST
ed:
It seems to me that List Items
is being passed, containing SchedulingViewModel
s and their associated Schedules
, but maybe not?
There are three relevant methods in the Controller. Here are their signatures:
public ActionResult ScheduleJob(int? id)
public ActionResult Table(int? id)
[HttpPost]
public ActionResult Table(ScheduleContainerViewModel cvm)
ScheduleJob
loads the initial View, which calls [HttpGet] Table
to load the PartialView. Finally, [HttpPost] Table
is the one being POST
ed to. Why can't the model binder see the data being passed to it in the XHR?
My only guess it that it's because the model used by the View
called by ScheduleJob
is different than the one being POST
ed to [HttpPost] Table
.