我有一个ASP.NET MVC包装类,它包装了一个包含ViewModels的List:
public class ScheduleContainerViewModel
{
public List<SchedulingViewModel> Items { get; set; }
public ScheduleContainerViewModel(List<SchedulingViewModel> items)
{
Items = items;
}
SchedulingViewModel
包含Schedule
个对象和Users
个对象。
ScheduleContainerViewModel
最终会传递给PartialView
。
通过Ajax调用此PartialView
来填充View
中的div。 PartialView
的模型为ScheduleContainerViewModel
,View
的模型为Job
。
Ajax GET很棒。但是,当我尝试POST
时,从不调用Controller,我收到500服务器错误。以下是POST
编辑的部分XHR数据:
在我看来,列表Items
正在传递,包含SchedulingViewModel
个及其关联的Schedules
,但可能不是?
Controller中有三种相关方法。以下是他们的签名:
public ActionResult ScheduleJob(int? id)
public ActionResult Table(int? id)
[HttpPost]
public ActionResult Table(ScheduleContainerViewModel cvm)
ScheduleJob
加载初始视图,调用[HttpGet] Table
加载PartialView。最后,[HttpPost] Table
是POST
编辑的View
。为什么模型绑定器可以看到在XHR中传递给它的数据?
我唯一的猜测是,因为ScheduleJob
调用的POST
使用的模型与[HttpPost] Table
<j:set var="myvar" value="${it.getAction('org.jenkinsci.plugins.workflow.cps.EnvActionImpl').getOverriddenEnvironment()}"/>
<p>My var: ${myvar}</p>
调用的模型不同。