我什么时候应该使用 WebForms 来提供用户正在寻找的用户体验,而不是混乱的 MVC?

发布于 2024-10-02 16:29:05 字数 662 浏览 3 评论 0原文

我一直在使用 MVC 重新实现我曾经使用 WebForms 构建的应用程序。我注意到以下内容:

  1. MVC 对于简单页面、不需要在请求之间维护大量状态的页面非常有效。如果页面需要任何复杂性,那么页面对 MVC 的纯粹遵守很快就会变成有漏洞的抽象,并在视图实现和控制器之间创建非常紧密的耦合。我对 MVC 的理解是,有一个控制器应该能够处理给定模型的多个视图,并且两者之间的分离非常清晰。

  2. 我看到的另一个摩擦点是 MVC 意味着业务规则是通过模型的设计来强制执行的(我喜欢这一点)。然而,当我构建我的应用程序时,我很快发现验证也应该在客户端进行(如果只是为了避免多个帖子的用户体验)。对我来说,这似乎是设计模式的另一种掺假,因为我不仅将业务逻辑存储在两个地方,而且还存储在两种语言中!

我遇到的问题是,虽然 WebForms 几乎无法让我控制 MVC 中提供的 UI 渲染和标记,但我对必须在视图中编写度量代码块以重新创建 WebForm 版本感到困惑我的应用程序并提供类似的用户体验。

那么,在进行 UI 设计和实现解决方案时,我应该如何考虑解决与经典 WebForms 方法不同的问题?另外,Mason-Dixon 线(它是否存在)是什么?我应该简单地使用 WebForms 尽可能轻松地提供用户正在寻找的用户体验,而无需创建混乱的 MVC 应用程序?

I've been using MVC to re-implement an application that I once built using WebForms. What I've noticed is the follow:

  1. MVC works really well for simple pages, pages that don't require large amounts of state to be maintained between requests. If the page requires any sophistication, then the purity of page's adherence to MVC quickly becomes a leaky abstraction and creates a very tight coupling between the View implementation and the controller. My understanding of MVC is that there is a single controller that should be able to handle multiple views of a given model with very clear and clean separations between the two.

  2. Another point of friction I'm seeing is that MVC implies that the business rules be enforced through the design of the model(which I love). However as I build my application I soon see that validation should live client-side as well(if for nothing other than the user experience of avoiding multiple posts). To me this seems another adulteration of the design pattern in that I'm storing business logic not only in two places but two languages as well!

The issue I have is that while WebForms doesn't give me nearly the control over the UI rendering and markup that is afforded me in MVC, I'm torn as to having to write metric gobs of code in the view to recreate the WebForm version of my application as well as deliver a similar user experience.

So when approaching UI design and implementing a solution, how should I think about solving the problem that differs from the classic WebForms approach? Also what is the Mason-Dixon line(does it even exist) where I should simply use WebForms to deliver the User Experience my users are looking for as easily as possible without creating a muddled MVC'ish application?

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

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

发布评论

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

评论(2

青春有你 2024-10-09 16:29:05

MVC 可以像 WebForms 一样维护状态。如果您确实需要的话,您仍然可以使用 Session 或 MVC TempData。

说你必须编写状态管理的度量标准有点夸张。 ViewState 之类的实现实际上非常容易创建。 ViewState 的核心只是将状态信息序列化并加密到 字段中。使用 MVC 模型绑定概念,这确实很容易实现。

您还应该考虑到,使用 MVC,花哨的 javascript 优点也变得更容易访问。事实上,在客户端浏览器上维护基于 javascript 的复杂向导或类似页面要容易得多,您甚至可能不需要使用 Session 或 TempData。

所有新的 MVC 开发人员在学习时最终都会遇到“状态管理墙”。 MVC 只是采用了不同的方法,您需要调整 WebForms 思维方式来应对。学习如何实现 Post/Get/Redirect 模式以及有效使用 javascript/ ajax 在这方面确实很有帮助。

对于 WebForms 开发人员来说,MVC 看起来既陌生又疯狂,但是一旦您克服了一些学习障碍,您就会真正开始像冠军一样飞行并保持状态。 :)


在哪里实施验证是您的选择,但不是必需的。 MVC 有助于从元数据自动生成客户端验证,因此几乎没有重复。您还应该考虑到验证邮政编码与实际业务逻辑之间存在很大差异。

MVC can maintain state just like WebForms does. You still have Session or in MVC TempData, if you really need it.

Saying you have to write metric gobs of state management is a little hyperbolic. ViewState like implementations are actually very easy to create. ViewState at its core is just serialized and encrypted state information into a <input type='hidden'> field. With MVCs model binding concepts this is really easy to implement.

You should also consider that with MVC fancy javascript goodness also becomes a lot more accessible. In fact it is so much easier to maintain complex javascript based wizards or similar pages on the client browser you may not even need to use Session or TempData.

All new MVC developers eventually run into the "state management wall" while learning. MVC just takes a different approach and you need to adjust your WebForms mindset to cope. Learning how to implement the Post/Get/Redirect pattern and effective use of javascript/ajax will really really help in that regard.

MVC just looks foreign and crazy to WebForms developers but once you get over some learning hurdles you'll really start flying and maintaining state like a champ. :)


Where you implement validation is your choice and its not required. MVC helps automate generating client side validation from metadata so there is very little duplication. You should also consider that there is a big difference between validating a zip code and then actual business logic.

我不会写诗 2024-10-09 16:29:05

关于 MVC 仅适用于简单页面,您是对的。如果您正在制作现实世界的应用程序,您将添加大量 Web 表单已提供的自定义代码。为了使 MVC 应用程序与 Web 窗体应用程序一样好,您无论如何都要放弃 MVC 的所谓好处,而要在 Web 窗体中堆积一些被认为不好的东西。 MVC 只是吸引不同开发人员的另一种方式,但实际上并没有为开发社区添加任何有价值的东西。

You are right about MVC being only good for simple pages. If you are making real world applications, you are adding lots of custom code that Web Forms is already providing. To make MVC applications work as good as Web Forms apps, you are giving up the so-called benefits of MVC anyway and are piling on things that are supposedly bad in Web Forms. MVC is just another way to attract a different set of developers but really is not adding anything worthwhile to the development community.

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