【发布时间】:2013-11-22 13:08:32
【问题描述】:
我有一个模型,我想要填写如下步骤: actionresult1(model)->actionresult2(model)-actionresult3(model)
我的模型是 Person:
public class Person{
string FirstName {get;set;}
string Lastname {get;set;}
int Age {get;set;}
}
在我的 PersonController 中,我有三个 ActionResult:
public ActionResult FillFirstName(Person model)//First page where i start. Model is empty
{
return View("~/Views/FillFirstName.cshtml", model);
}
public ActionResult FillLastName(Person model)//Second page, where first name is filled
{
return View("~/Views/FillLastName.cshtml", model);
}
public ActionResult FillAge(Person model)//When i click submit button in FillLastName.cshtml view then it submits form here and model have filled only LastName and FirstName is empty.
{
return View("~/Views/FillAge.cshtml", model);
}
而我的三个观点是:
1)FillFirstName.cshtml
@using (@Html.BeginForm("FillLastName", "Person"))
{
@Html.TextBoxFor(m => m.FirstName)
<input type="submit" name="Next" value="Next" />
}
2)FillLastName.cshtml
@using (@Html.BeginForm("FillAge", "Person"))
{
@Html.TextBoxFor(m => m.LastName)
<input type="submit" name="Next" value="Next" />
}
3)FillAge.cshtml
@using (@Html.BeginForm("NextAction", "Person"))
{
@Html.TextBoxFor(m => m.Age)
<input type="submit" name="Next" value="Next" />
}
问题:当我尝试在视图之间传递模型时,它只包含我在上一个视图中提交的数据。
原因:我已经形成了 2000 行,我想把它切成小块。
有没有什么办法可以使用 Viewbag 或 ModelState 或其他东西来让模型充满我在前几页提交的所有数据?有人可以给我一些例子吗? :)
【问题讨论】:
-
如果您愿意,可以使用 Session
标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-viewmodel