如何提交包含 PagedList 的表单?
模型:
public class PagedClientViewModel
{
public int? Page { get; set; }
public PagedList.PagedList<ClientViewModel> Clients { get; set; }
}
public class ClientViewModel
{
public int ClientId { get; set; }
public string Name { get; set; }
public bool IsCool { get; set; }
}
看法:
@model MvcApplication21.Models.PagedClientViewModel
@{
ViewBag.Title = "Index";
}
@using (Html.BeginForm("index", "home"))
{
foreach (var item in Model.Clients)
{
<div>
@Html.HiddenFor(modelItem => item.ClientId)
@Html.EditorFor(modelItem => item.Name)
@Html.CheckBoxFor(modelItem => item.IsCool)
</div>
}
<input type="submit" value="submit" />
}
看法:
public ActionResult Index()
{
List<ClientViewModel> clients = new List<ClientViewModel>();
ClientViewModel client1 = new ClientViewModel
{
ClientId = 1,
Name = "Bob",
IsCool = false
};
ClientViewModel client2 = new ClientViewModel
{
ClientId = 2,
Name = "John",
IsCool = false
};
ClientViewModel client3 = new ClientViewModel
{
ClientId = 3,
Name = "Peter",
IsCool = true
};
clients.Add(client1);
clients.Add(client2);
clients.Add(client3);
PagedClientViewModel model = new PagedClientViewModel
{
Page = 1,
Clients = new PagedList<ClientViewModel>(clients, 1, 10)
};
return View(model);
}
[HttpPost]
public void Index(PagedList<ClientViewModel> model)
{
//how do i process the model here?
}
}
我收到以下错误:
没有为此对象定义无参数构造函数。
这样做的正确方法是什么?我需要使用编辑器模板吗?