Questions tagged «post-redirect-get»

10
Asp.net MVC ModelState.Clear
谁能给我关于Asp.net MVC中ModelState角色的简要定义(或指向其中的链接)。特别是我需要知道在什么情况下有必要或希望致电ModelState.Clear()。 有点开放了吧 ...抱歉,如果告诉您我在做什么,可能会有所帮助: 我在名为“页面”的控制器上进行了“编辑”操作。当我第一次看到用于更改Page详细信息的表单时,所有内容都会正常加载(绑定到“ MyCmsPage”对象)。然后,我单击一个为MyCmsPage对象的字段之一生成值的按钮(MyCmsPage.SeoTitle)。它会很好地生成并更新对象,然后我将返回带有新修改的页面对象的操作结果,并期望相关的文本框(使用渲染<%= Html.TextBox("seoTitle", page.SeoTitle)%>)会被更新……但是,它会显示已加载的旧模型中的值。 我已经通过使用来解决它,ModelState.Clear()但是我需要知道它为什么/如何工作,所以我不仅仅是盲目地做。 PageController: [AcceptVerbs("POST")] public ActionResult Edit(MyCmsPage page, string submitButton) { // add the seoTitle to the current page object page.GenerateSeoTitle(); // why must I do this? ModelState.Clear(); // return the modified page object return View(page); } Aspx: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MyCmsPage>" …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.