ASP.NET MVC (which stands for Model-View-Controller) offers a dramatically different way to build web
pages than the standard web forms model. The core idea is that your application is separated into three
logical parts. The model includes the application-specific business code—for example, data-access logic
and validation rules. The view creates a suitable representation of the model by rendering it to HTML
pages. The controller coordinates the whole show, handling user interactions, updating the model, and
passing the information to the view.
The MVC pattern sidelines several traditional ASP.NET concepts, including web forms, web
controls, view state, postbacks, and session state. As a result, it forces developers to adopt a new way of
thinking (and accept a temporary drop in productivity). To some, the MVC pattern is cleaner and more
suited to the Web. To others, it’s extra effort with no clear payoff. But if any of the following points are
important to you, it’s worth at least considering ASP.NET MVC:
Test-driven development: Thanks to the clean separation of parts in an ASP.NET MVC application,
it’s easy to create unit tests that exercise it. With web forms, automated testing is tedious and often
impossible.
Control over HTML markup: With web forms, you program against a rich set of objects that take
care of state management and HTML rendering. With ASP.NET MVC, you inject content in a way
that’s more like data binding. While this means that complex formatted pages may take more work
to design, it also means that you have complete control over every markup detail. This control is
useful if you plan to write client-side JavaScript or use a third-party JavaScript library like jQuery.
(On the other hand, if you aren’t comfortable or interested in mucking around with HTML, web
forms is probably a better framework for your applications.)
Control over URLs: Although ASP.NET continues to give developers more control over URL routing,
ASP.NET MVC has the concept built-in. Controllers handle the mapping between URLs and your
application logic, which means it’s easy to use URL configurations such as /Products/List/Beverages
instead of /Products/List.aspx?category=Beverages. These clear, readable URLs make search-engine
optimization easier and more effective.
On the other hand, if you prefer to have rapid application design, a high-level model that manages
state for you, and a range of rich web controls, web forms will probably remain your first choice
development model.
Most of this book focuses on web forms, ASP.NET’s core model. You’ll get an introduction to
ASP.NET MVC in Chapter 32. For much more information, you can visit the official ASP.NET MVC
website at http://www.asp.net/mvc, or refer to the excellent book Pro ASP.NET MVC Framework by
Steven Sanderson (Apress, 2009).
Hiç yorum yok:
Yorum Gönder