Moving from ASP.NET Web Forms to ASP.NET MVC

Preview:

Citation preview

Moving from ASP.NET WebForms to ASP.NET MVC - Is it really worth it?

Kim Painter@kgpainterkimpainter1984@gmail.com

What Are Our Choices?

Strengths of ASP.NET Web Forms over MVC

Provides:

Familiar control and event based programming model

Rich controls that encapsulate HTML, CSS & Javascript

Availability of many rich controls

Browser differences handled for you

SharePoint builds on Web Forms

The Background of MVC

The MVC pattern was invented in the '70s as part of Smalltalk.

MVC divides your UI into three distinct objects:

the controller, which receives and handles input; the model, which contains your domain logic; and the view, which generates your output.

Strengths of ASP.NET MVC over Web Forms

Provides:

A "separation of concerns”

Significant control over rendered HTML

Supports Unit Testing, TDD and Agile methodologies

Encourages the use of design patterns by convention

Encourages more prescriptive applications

Extremely flexible and extensible

Guidelines for When to use Which

By Nick Berardi

Using a Decision Flow

By Vaibhav Jain

If We Know There Are Benefits to Learning and Programming With MVC Then Why Don’t We?

Time Challenges/ Priorities

Balancing Life

Comfort Zone Disinterested/

Apathetic

Other Challenges

“Many companies have a huge investment in Web Forms technology that they just simply aren't going to throw out - training, third party controls, experience and so on. “

“Many companies don't buy into the whole Unit Test pitch behind MVC. Many companies simply don't test at all.”

Quotes from Mike Brindhttp://mikesdotnetting.com/

Motivators – Following Words of Wisdoms

If you always do what you've

always done, you'll always

get what you always gotYou can't discover new oceans unless you have the courage to leave the shore.

Side Benefits

“Developers can grow stronger

by stretching themselves and

learning new ideas and

approaches. “

“Even if you don’t ultimately use something new directly, the act of learning it can sharpen you in positive ways.”

Quotes from Scott Guthrie’s blog on About Technical Debates (and ASP.NET Web Forms and ASP.NET MVC debates in particular)

Commonalities from the Core Runtime

AuthenticationAuthorizationUser MembershipRole SecurityOutput CachingSession StateConfigurationDeploymentAjaxothers...

Web Forms & MVC Conversion & Integration

Conversion ProjectSide-By-Side – Preexisting Web Forms appSide-By-Side – New MVC app

Side-By-Side – Preexisting Web Forms app

http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx

Side-By-Side – New MVC app

Why?

Keeping rich functionality of some desired server controls – such as the Report Viewer

http://weblogs.asp.net/rajbk/archive/2010/05/11/running-asp-net-webforms-and-asp-net-mvc-side-by-side.aspx

Common Master Page

Root.master <%@ Master Inherits="System.Web.UI.MasterPage" … %>

MVC.master <%@ Master MasterPageFile="~/Views/Shared/Root.Master" Inherits="System.Web.Mvc.ViewMasterPage" … %>

WebForm.master <%@ Master MasterPageFile="~/Views/Shared/Root.Master" Inherits="NorthwindSales.Views.Shared.Webform" %>

Code behind: public partial class Webform : System.Web.UI.MasterPage {}

Demo

So back to the question…

Is it really worth moving from ASP.NET WebForms to ASP.NET MVC?

It depends

Resources:Comparison Sites:

http://coderjournal.com/2008/12/introducing-aspnet-mvc-part-2-aspnet-mvc-vs-webforms/http://blog.gadodia.net/choosing-between-webforms-and-mvc/http://msdn.microsoft.com/en-us/magazine/dd942833.aspxhttp://www.asp.net/web-forms/videos/how-do-i/choosing-the-right-programming-model

Converting from Web Forms to MVC:http://codingatilivedigitally.wordpress.com/2012/07/10/9-steps-to-switch-from-asp-net-web-forms-to-mvc/

http://www.asp.nethttp://aspdotnetmvc.com/

ASP.NET MVC in Action (1-4)Programming Microsoft ASP.NET MVC Programming Microsoft ASP.NET 4