<%:ViewData["galleryId"]%>
<% using (Html.BeginForm(
"FinishEdit" ,
"GalleryManager" ,
FormMethod.Post ,
new { enctype = "multipart/form-data" }
)
)
{%>
<%:Html.Hidden("galleryId" , ViewData["galleryId"])%>
<% } %>
表单外的 View 数据正确呈现,但表单内的 viewdata
没有。这是怎么回事?
最佳答案
如果您打算修改任何 POSTed 变量并呈现相同的 View ,请尝试在 Controller 操作中清除模型状态:
[HttpPost]
public ActionResult FinishEdit()
{
...
ModelState.Remove("galleryId");
ViewData["galleryId"] = "some new gallery id";
return View();
}
Html 助手首先在 ViewData 和 Model 之前查看模型状态字典值。
关于asp.net-mvc - 如何让窗体中的 ViewData 正确显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5112499/