我正在一个用户登录并可以在活动表单中输入信息的 MVC 网站上工作。提交后,它会显示结果。假设该人访问网站上的其他链接,然后决定返回活动表单。有没有办法让我的用户的表单字段、下拉框、滑块位置等仍然得到维护?唯一不应该维护表单的时间是在用户注销之前。
到目前为止,这是我的代码:
查看 - 活动
@model Project.Models.ActivityModel
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
@Html.TextBoxFor(x => x.Activity_CityName)
<div class="editor-label">
<strong>@Html.LabelFor(x => x.Activity_StartDate)</strong>
</div>
<div class="editor-field">
<input id="checkin" type="text" name="Activity_StartDate" />
</div>
@Html.TextBoxFor(x => x.Activity_EndDate)
@Html.DropDownListFor(x => x.Activity_NumAdults, AdultNum)
@Html.DropDownListFor(x => x.Activity_NumChildren)
@Html.DropDownListFor(x => x.Activity_ChildAge1, ChildAge)
@Html.DropDownListFor(x => x.Activity_ChildAge2, ChildAge)
@Html.DropDownListFor(x => x.Activity_ChildAge3, ChildAge)
<div class="submitbutton">
<input data-inline="true"type="submit" id="activity_search" value="Search" />
</div>
}
结果视图 - Activities_FormSuccess
@model Project.Models.ActivityModel
<p>City: @Model.Activity_CityName</p>
<p>StartDate: @Model.Activity_StartDate</p>
<p>EndDate: @Model.Activity_EndDate</p>
<div>
<p><strong>Ticket</strong></p>
<p>Number of Adults: @Model.Activity_NumAdults</p>
<p>Number of Children: @Model.Activity_NumChildren</p>
<p>Child 1 age: @Model.Activity_ChildAge1</p>
<p>Child 2 age: @Model.Activity_ChildAge2</p>
<p>Child 3 age: @Model.Activity_ChildAge3</p>
</div>
控制器
public ActionResult Activities()
{
return View();
}
[HttpPost]
public ActionResult Activities(ActivityModel activitysubmission)
{
return View("Activities_FormSuccess", activitysubmission);
}