将模型对象发布到控制器中( ASP.NET MVC)
资 源 简 介
翻译 maninwest@Codeforge 作者:Saswat Mohanty@CodeProject
我们想在 HttpPost 时将视图中的模型对象列表发布到控制器中。很多开发员尝试通过数组获得数据列表。但是,有个简单的方法可以不用数组获取模型对象的列表。创建一个 ASP.NET MVC 4 应用程序。首先在解决方案的 Model 文件夹中创建两个模型类,例如 EmployeeModelClass.cs 和 DepartmentModelClass.cs 。
模型
public class EmployeeModelClass
{
public string Name { get; set; }
public string Address { get; set; }
public string Contact { get; set; }
public IEnumerable DeptList { get; set; }
}
public class DepartmentModelClass
{
public string DepartmentCode { get; set; }
public string DepartmentName { get; set; }
}
控制器
public class EmployeeController : Controller
{
//
// GET: /Employee/
public ActionResul
文 件 列 表
MvcApplication5
packages
MvcApplication5
MvcApplication5.sln
MvcApplication5.v11.suo