【发布时间】:2015-04-05 01:54:32
【问题描述】:
所以我的问题很简单。提交我的表单后,所有表单值都将被删除。
查看 Stackoverflow 上提出的问题让我觉得大多数人都有相反的问题,这是默认行为?
反正我的观点很简单
@using (Html.BeginForm("Index", "Default"))
{
<input type="text" name ="FirstName" />
<input type="text" name="LastName" />
<input type="submit" value="Send" />
}
这里是控制器。
public class DefaultController : Controller
{
// GET: Default
public ActionResult Index()
{
var model = new FormViewModel();
return View(model);
}
[HttpPost]
public ActionResult Index(FormViewModel model)
{
return View(model);
}
}
我的视图模型
public class FormViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
提交后我的输入字段为空。如何在输入字段中保留值? (在现实生活中我当然有更大的形式)
【问题讨论】:
-
使用 Ajax.BeginForm 而不是 Html.BeginForm
-
不会改变任何东西。仍然是相同的行为。
标签: c# asp.net-mvc forms razor postback