English 中文(简体)
保存更改后未刷新的依赖字段
原标题:Dependent field not refreshing after saving changes

我有一个视图, 显示“ 开始日期 ” 和“ 结束日期 ”, 以及一个只读字段, 显示两个日期之间的天数。 所有这些字段都与我的模型捆绑在一起, 在剃刀视图定义中采用标准@ Html. Editorfor () 方法 。 当我修改其中的一个日期并单击“ 保存” 时, 将

[HttpPost]
ViewResult Edit([modeltype] editedModel){
 ... }

在将新日期和计算值保存到数据库之前,计算并设置计算字段的新值,然后用更新模型返回“视图” 。我的问题是,视图没有显示新计算值(而不是按初始页面负荷显示原始计算值) 。直到我离开和返回到该视图时,它正确显示计算值。了解我错过了什么吗?浏览器是否显示在我 HttpPost 之后的页面的缓存版本? 如果如此,我是否可以禁用此行为?

最佳回答

Html 助手更喜欢 < code> model State Collection 而不是实际的 < code> model 。 这意味着他们将显示已张贴的值, 而不是您在控制器中更新的值 。

如果您想要返回您在动作中的相同模型, 并且您已经更改了某些值, 在返回您的模型之前, 您需要清除 < code> 模式状态 :

[HttpPost]
public ViewResult Edit(MyModel editedModel)
{

   //set some properties on editedModel

   ModelState.Clear();
   return View(editedModel);
}
问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签