如果我有了一个模型的视图,可以说汽车另一种模式..发布到在ASP.NET MVC形式
@model Project.Car
这个观点我想创建一个将数据发送到表单中一种新的模式
@using (Html.BeginForm("Add", "Controller"))
{
@Html.Hidden("ID", "1")
@Html.Hidden("UserID", "44")
@Html.TextArea("Description")
}
我发现,如果我的动作与定义我的ViewModel它不工作(模型总是空):
[HttpPost]
public PartialViewResult Add(ViewModels.NewModel model)
但是,如果我使用的FormCollection它的工作原理:
[HttpPost]
public PartialViewResult Add(FormCollection formCollection)
这里是视图模型:
public class NewModel
{
public int ID { get; set; }
public int UserID { get; set; }
public string Description { get; set; }
}
我的问题是,我可以从我的表单POST数据为newModel?它所处的视图与Project.Car绑定是正确的。它是页面上的一个小表单,需要发布与Project.Car无关的一组不同的数据。
你可以发布ViewModel吗? – brenton 2013-02-26 16:22:57
当然,只是添加它。 – Alex 2013-02-26 16:25:50
但是您正在发布Project.Car。你不是吗? – idipous 2013-02-26 16:26:30