O'Reilly logo

Beginning ASP.NET MVC 1.0 by Keyvan Nayyeri, Simone Chiaretta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 10. Components

With ASP.NET MVC, you gain a cleaner way to separate the responsibilities of a Web application and an easier testing experience. Because it's a complete break with the traditional WebForm model, however, it lacks some of WebForms' basic features.

The feature of WebForms you are going to miss the most is server controls. How are you going to achieve the same results using ASP.NET MVC? Can it still be achieved?

In this chapter you see how to encapsulate some portions of your application in components that can be reused in many of your views.

You learn:

  • How to use the server controls

  • How to exploit the partial views

  • How to include behaviors in your components

Before talking about how to achieve this result with ASP.NET MVC, it's important to see why using the server controls available from WebForms is not the best solution anymore.

Why Are There No Server Controls?

The traditional use of server controls won't work with ASP.NET MVC for a couple of reasons.

Reason number one: For a server control to handle its own interactions, the post operation needs to always go back to the same page where the controller has been declared. This was done by using the infamous postback concept that is not used in ASP.NET MVC.

Reason number two: The control has to manipulate things only inside its boundaries and everything that is outside must be sent back to the user as it was before. Again, this was achieved by storing all the contents of a page inside the viewstate of the page. This abstraction ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required