What is the ‘page lifecycle’ of an ASP.NET MVC page, compared to ASP.NET WebForms?

I’ll attempt to comment on each of the bullet points you mentioned:

Your master pages still exist in MVC and are used to provide a consistent layout to the site. not much new there.

Your content pages will become views in the MVC world. They still provide the same content areas to your master pages.

The eventhandling of webforms should not be used in MVC, instead your Controller classes and their action methods will handle loading your data into a “model” that gets passed to the view.

Although webform style databinding is possible in MVC, I find that it is not the optimal solution. Better to place your data in a model class and strongly type your view so that you have direct access to that model. Then its simply a matter of using the <%= ViewData.Model.SomeProperty %> syntax to access your data and display it in the desired locations. As for viewstate, my recommendation is to forget that it even exists.

Remember that one of the advantages of using MVC is that you have control over the HTML you send to the client. Embrace that power and try to find solutions that allow you to maintain that control. Webform controls attempt to hide the the html from you and as such make it more difficult to customize the html when you need to.

I would highly recommend JQuery or one of the other similarly powerful javascript libraries. But learn to use them to access the HTML DOM directly and avoid the id mangling issues of webform controls.

You can use jquery to hook into the dropdown selection on the client side and submit standard or ajax style requests. Those request can return new pages, redirects, html fragments or even JSON data that can be used to update the existing page.

The asp.net Session can be used as needed.

Leave a Comment