开发者

In my ASP.NET MVC app how can I determine if any property in my domain Model has changed?

I am working on the MVC prototype of a very large and complex ASP.NET 2.0 Webforms based business product suite for an organization. One of the capabilities inbuilt into the existing app is that it only hits the database to store a result set if the user made any changes at all on the Webforms UI. The web app has a complete layer built in to track this "if changed by user" thing.

I was wondering if within ASP.NET MVC there is a provision/functionality to determine what property was changed by the user on the view? The idea is simple, user sees a view, probably makes some changes and hits "Save". The controller that accepts the post needs to figure out if the state of the model was changed by the user or not and save it only if the state was changed.

Any thoughts?

PS: I am tagging this as mvc-2 and mvc-3 as it is a prototype. I am currently learning/developing this in MVC 2 but will quickly move to MVC 3 if that suits our needs开发者_Go百科 better!


I was wondering if within ASP.NET MVC there is a provision/functionality to determine what property was changed by the user on the view?

No, there is nothing to do this in MVC. WebForms does this by including the original values of fields in the view state, but in embracing the statelessness of HTTP at its core MVC doesn't do this.

If your (view) model types are regular enough you might be able to construct scaffolding to do this (and the more types you have the more benefit to do this). I've prototyped something on these lines where each view model type determines if there have been changes when updating the model type before any update to the database (and thus bypasses the update).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜