我有以下代码:
public ViewResult test(testModel model)
{
if (ModelState.IsValid)
{
SaveData(model);
}
testModel.Name = "testing returned view data";
return View("TestManage", model);
}
TestManage视图已
@model testModel
并拥有文本框
@Html.EditorFor(model => model.Name)
为什么视图不反映新的testModel.Name数据?我错过了什么或者这是一个更大问题的一部分吗?
答案 0 :(得分:0)
您需要清除ModelState ModelState.Clear() 或者你可以这样:
public ViewResult test(testModel model)
{
if (ModelState.IsValid)
{
SaveData(model);
}
ModelState["Name"].Value = "testing returned view data";
return View("TestManage", model);
}
您可以找到更多详细信息here
答案 1 :(得分:0)
使用ModelState.Clear()
public ViewResult test(testModel model)
{
if (ModelState.IsValid)
{
SaveData(model);
}
testModel.Name = "testing returned view data";
ModelState.Clear();
return View("TestManage", model);
}