我什么时候以及为什么应该考虑asp.net MVC? [英] When and why should I consider asp.net MVC?

查看:25
本文介绍了我什么时候以及为什么应该考虑asp.net MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到最近有很多关于 asp.net MVC 的讨论,但我没有遇到关于何时、何地或为什么要通过 WebForms 使用它的清晰或令人信服的描述.

I've noticed a lot of talk about asp.net MVC lately, but I haven't come across a clear or compelling description of when, where or why I would want to use it over WebForms.

假设我想构建一个小型 Web 应用程序,允许人们在线宣传某些项目.该网站将有 4 个用例:

Let's say I wanted to build a small web application that allows a person to advertise some items online. The website will have 4 use cases:

  • 搜索广告
  • 查看房源
  • 查看项目
  • 投放广告

让我们假设:

  • 我对控制器的单元测试并不是特别感兴趣.该页面要么正确呈现项目列表,要么不呈现.
  • 我对更好地控制 HTML 标记感兴趣.
  • 我对使用最新的 buzz 技术不感兴趣.
  • 我有兴趣使用在生产力、性能、可维护性和可维护性方面最适合工作的工具最终解决方案的简单性.
  • 我不想为了让一些简单的事情工作而必须解决一堆细微差别.

所以,我的问题是:

  • 这两种模型之间的根本区别是什么?
  • 在哪种情况下,一种比另一种更好?
  • asp.net MVC 的问题是什么(我知道 WebForms 的问题)
  • 对于我们的示例应用程序,使用 asp.net MVC 而不是 WebForms 可以获得什么?
  • 对于我们的示例应用程序,使用 asp.net MVC 而不是 WebForms 会丢失什么?
  • 在同一个小型应用程序中混合和匹配模型是否可行?

感谢所有花时间提供答案的人.

Thanks to anyone who spends the time to contribute an answer.

推荐答案

  • 这两种模型之间的根本区别是什么?

WebForms 试图通过允许您重用大量预制控件以及通过隐藏的 _VIEWSTATE 机制伪造 Web 应用程序状态来模仿 WinForms 开发.

WebForms try to mimic WinForms development by allowing you to reuse lots of pre-made controls, and by faking web application state via the hidden _VIEWSTATE mechanism.

MVC 是一种旨在帮助您分离数据(Model)、业务逻辑(Controller)和表示(View)的模式.它更符合网络的真实本质:RESTful URL,无状态.

MVC is a pattern designed to help you separate your data (Model), business logic (Controller) and presentation (View). It adheres more to the true nature of the web : RESTful URLs, stateless.

  • 在哪种情况下,一种比另一种更好?

在我看来,对于大量使用控件的 Intranet 应用程序,WebForms 在减少开发时间方面非常有用,因为有了设计器,您可以非常快速地创建 UI,并让框架自动管理应用程序的状态.

In my opinion, for an intranet application making heavy usage of controls, WebForms can be useful at reducing development time, because thanks to the designer you can create your UI very quickly and let the framework manage the app's state automatically.

对于任何其他项目,尤其是公共网站,即使是很小的网站,我认为 MVC 是可行的方法.

For any other project, especially a public website, even a small one, I think MVC is the way to go.

  • asp.net MVC 有哪些问题(我知道有哪些问题)网络表单)

我认为要完全理解 MVC 模式及其功能需要一些学习曲线.此外,由于该框架仍处于 BETA 阶段,您可以预期 API 在发布前会经历一些细微的变化.

I'd say there is some learning curve to fully understand the MVC pattern and its power. Also, since the framework is still in BETA you can expect the API to experience some minor changes before release.

由于 JavaScript 在 MVC 中不会对您隐藏,因此如果您不熟悉它,也需要一些时间来学习.jQuery 大大简化了这一点.

Since JavaScript is not hidden from you in MVC, it would also require some time to learn if you're not familiar with it. jQuery greatly simplifies this though.

  • 对于我们的示例应用程序,使用 asp.net MVC 而不是网络表单?

您将更好地控制 HTML 标记和 Javascript 行为,更清晰地分离关注点和一些易于测试的代码库(即使您似乎对单元测试不感兴趣).

You'd gain better control over HTML markup and Javascript behavior, a cleaner separation of concerns and some easily testable codebase (even if you don't seem interested in unit testing it).

  • 对于我们的示例应用程序,使用 asp.net MVC 而不是我会失去什么网络表单?

您将失去构建页面和应用程序状态管理的拖放"快捷方式.

You'd lose the 'drag and drop' quick way of building your pages and the application state management.

  • 在同一个小范围内混合和匹配模型是否可行?申请?

在某些方面,似乎是的.

In some ways, yes it seems.

我建议您观看 Phil Haack 的这个演讲,他很好地概述了框架,并邀请 Jeff Atwood 谈谈他如何用它构建 StackOverflow.

I'd recommend watching this talk by Phil Haack, who gives a good overview of the framework and invites Jeff Atwood to talk about how he built StackOverflow with it.

他解释了 SO 如何将一些 WebForms 控件用于 CAPTCHA,这些控件将自身呈现到视图中.

He explains how SO is using some WebForms controls for CAPTCHAs which render themselves into the view.

这篇关于我什么时候以及为什么应该考虑asp.net MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆