Skip to content

jpoehls/WebFormsToMvcDemo

Repository files navigation

ASP.NET WebForms to MVC & jQuery:
Real-world tricks to make the switch

These demos were originally built for Tulsa TechFest 2011.

Synopsis

Have WebForms? Want MVC? No time to rewrite? You don't have to!

Come watch as we transform a pseudo-production application from WebForms to MVC using best practices and incremental strategies that you can use on your own projects!

Along the way we'll see:

  • how MVC makes your life easier
  • ways to incrementally migrate your app to MVC without a big rewrite
  • common pitfalls (and solutions!) on the path from WebForms to MVC
  • leveraging jQuery as a replacement for the <asp:UpdatePanel />, <asp:GridView />, and more!
  • how to structure your JavaScript in a testable way

No slides. This will be a live coding event with unit tests along the way. I'll be showing off testing both controllers and JavaScript! You are definitely going to learn something in this session!

Steps to add MVC 3 to Web Forms 4 project

Hanselman's Steps

Add these folders and files to the root of your Web Forms project:

  • Content
  • Controllers
  • Models
  • Scripts
  • Views
  • Global.asax

Add these references to your Web Forms project:

  • Microsoft.CSharp
  • System.Web.Mvc
  • System.Web.WebPages
  • System.Web.Razor
  • System.ComponentModel.DataAnnotations

Make the following changes to Web.config.

<appSettings>

       

<compilation debug="true" targetFramework="4.0">

                              

<system.web>

                                                                   </system.web>

<!-- for IIS7 (including IIS Express) -->
<system.webServer>

      </system.webServer>

<!-- avoid issues if you have MVC 1 or 2 in your GAC -->
<configuration>

                                              

Update your Global.asax.cs:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
	filters.Add(new HandleErrorAttribute());
}

public static void RegisterRoutes(RouteCollection routes)
{
	routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

	routes.MapRoute(
		"Default", // Route name
		"{controller}/{action}/{id}", // URL with parameters
		new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
	);

}

protected void Application_Start()
{
	AreaRegistration.RegisterAllAreas();

	RegisterGlobalFilters(GlobalFilters.Filters);
	RegisterRoutes(RouteTable.Routes);
}

Add {E53F8FEA-EAE0-44A6-8774-FFD645390401}; to the <ProjectTypeGuids> in the web project file.

About

WebForms -> MVC demos for Tulsa TechFest 2011

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages