我在 MVC 3 项目中的观点有一个奇怪的问题。我有一个用于数据编辑的标准视图(使用模板创建)。当我提交表单时,我更改了Name
属性,但是当我从控制器返回浏览器后,我仍然可以看到该lorem
值。为什么 ?
@using (Html.BeginForm())
{
@Html.EditorFor(model => model.Name)
<input type="submit" value="Save" />
}
public ViewResult EditUserData(int id)
{
[...]
UserData model = new UserData();
model.Name = "lorem";
return View("~/Views/UserDetails.cshtml", model);
}
[HttpPost]
public ViewResult EditUserData(UserData model)
{
model.Name = "ipsum";
return View("~/Views/UserDetails.cshtml", model);
}
public class ControlUserData
{
[...]
[Required]
[Display(ResourceType = typeof(Resources), Name = "UserNameFirst")]
public string Name { get; set; }
}