我有一个包含 2 个输入类型 = 文本的页面。
@model MVC3.ViewModel.TalkToUsVM
@using (Html.BeginForm())
{
<ul>
<li>@Html.TextBoxFor(m => m.TalkToUsRequest.Name)</li>
<li>@Html.TextBoxFor(m => m.TalkToUsRequest.Email)</li>
</ul>
<input type="submit" value="Save"/>
}
在我的控制器中,我这样做:
[HttpPost]
public ActionResult Create(TalkToUsRequest talkToUsRequest)
{
var vm = new TalkToUsVM();
if (TryValidateModel(talkToUsRequest))
{
vm.Result = "Success";
return View("Create",vm);
}
vm = new TalkToUsVM
{
Result = "Errrooooooor",
TalkToUsRequest = talkToUsRequest
};
return View(vm);
}
所以问题..当我的模型有效时,我将结果设置为“成功”,此时 vm.TalkToUsRequest 为空..但是当页面呈现时,所有字段的值与我提交时的值相同..甚至我设置 vm.TalkToUsRequest = null!!如何清除此字段?