我从后台传递了一个强类型Model到前台显示,然后前台建立一个Html.BeginForm表单,并通过object routeValues将整个Model传回后台,但后台接收不到该对象里面的复杂类型数据,具体代码如下:
Model:
public class FooterViewModel
{
public string CompanyName { get; set; }
public string Year { get; set; }
}
public class BaseViewModel
{
public string UserName { get; set; }
public FooterViewModel FooterData { get; set; }
}
public class OperateEmployeeViewModel : BaseViewModel
{
public int ID { get; set; }
.......
.......
}
View:
@model MVCExample.ViewModels.OperateEmployeeViewModel
@{
ViewBag.Title = "DeleteEmployee";
}
<h2>Delete Confirmation</h2>
@using (Html.BeginForm("DeleteEmployee", "Employee", Model, FormMethod.Post))
{
<table>
<tr>
<td>
First Name:
</td>
<td>
@Html.DisplayFor(x => x.FirstName)
</td>
</tr>
......
}
Controller:
public ActionResult DeleteEmployee(OperateEmployeeViewModel operateEmployee, string BtnSubmit)
{
switch (BtnSubmit)
{
case "Delete":
Employee e = new Employee();
.........
.........
return RedirectToAction("Index");
case "Cancel":
return RedirectToAction("Index");
}
return new EmptyResult();
}
打了断点,可以看到从后台其他action传递到前台的强类型Model中,FooterData数据不是null的,但从前台beginform传递到后台,action接收到的FooterData却是null,请问这是怎么回事,要怎么解决?