在我的 ASP.NET MVC 应用程序中,如何确定我的域模型中的任何属性是否已更改?

发布于 2024-11-06 01:52:45 字数 387 浏览 0 评论 0原文

我正在为一个组织开发一个非常大且复杂的基于 ASP.NET 2.0 Webforms 的业务产品套件的 MVC 原型。现有应用程序内置的功能之一是,如果用户在 Webforms UI 上进行了任何更改,它只会访问数据库来存储结果集。 Web 应用程序内置了一个完整的层来跟踪“如果用户更改”的情况。

我想知道 ASP.NET MVC 中是否有一个规定/功能来确定用户在视图上更改了哪些属性?这个想法很简单,用户看到一个视图,可能会进行一些更改并点击“保存”。接受帖子的控制器需要确定模型的状态是否被用户更改,并且仅在状态更改时才保存。

有什么想法吗?

PS:我将其标记为 mvc-2 和 mvc-3,因为它是原型。我目前正在 MVC 2 中学习/开发此功能,但如果它更适合我们的需求,我将很快转向 MVC 3!

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 better!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难理解 2024-11-13 01:52:45

我想知道 ASP.NET MVC 中是否有一个规定/功能来确定用户在视图上更改了哪些属性?

不,MVC 中没有什么可以做的。 WebForms 通过在视图状态中包含字段的原始值来实现这一点,但在其核心中拥抱 HTTP 的无状态性,MVC 并没有这样做。

如果您的(视图)模型类型足够规则,您也许可以构建脚手架来执行此操作(并且类型越多,执行此操作的好处就越大)。我已经对这些行进行了原型设计,其中每个视图模型类型确定在对数据库进行任何更新之前更新模型类型时是否存在更改(从而绕过更新)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文