问题描述
我注意到很多谈论asp.net MVC的最近,但我还没有碰到过一个明确的或令人信服的说明来的时候,在哪里,为什么我会想使用它在的WebForms。
比方说,我想建立一个小型Web应用程序,允许一个人在线广告的一些项目。该网站将有4个用例:
- 搜索广告
- 查看列表
- 查看项目
- 将一个广告
让我们假设:
- 我没有单元测试我的控制器特别感兴趣。该页面将不是正确呈现的项目列表,或者不会。
- 我感兴趣的是在HTML标记的更多控制。
- 我不热衷于使用最新的嗡嗡声技术只是为了它的缘故。
- 我感兴趣的使用工具,是最适合在生产效率,性能,可维护性和放大器方面的工作;最终解决方案的简单性。
- 我不希望有解决一堆的细微差别来获得一些简单的工作。
所以,我的问题是这样的:
- 什么是两个模型之间的根本区别?
- 在这情况下比其他? 一个人好
- 什么是与asp.net MVC(我知道用的WebForms的陷阱中) 的陷阱
- 对于我们的示例应用程序,你会得到我通过使用替代的WebForms asp.net MVC?
- 对于我们的示例应用程序,你会失去我用,而不是WebForms的asp.net MVC?
- 是它可行的混合和匹配模式?
同样的小应用程序中的
由于任何人谁花时间来贡献一个答案。
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 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.
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.
For any other project, especially a public website, even a small one, I think MVC is the way to go.
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.
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.
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).
You'd lose the 'drag and drop' quick way of building your pages and the application state management.
In some ways, yes it seems.
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.
He explains how SO is using some WebForms controls for CAPTCHAs which render themselves into the view.
这篇关于当,为什么我应该考虑asp.net MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!