Sunday, May 2, 2010

ASP.NET 4 WinForms inside an MVC project

Hi,

I was stunned today watching a presentation by Scott Hanselmann about the new features of .NET 4 especially the fact that you can actually compose in a WebForms page into an MVC application using routing and it all just works!

Imagine you have like a regular MVC 2.0 app and for this one thing that you need to implement having a form instead of a controller and view would be soooo much easier. Now with this simple line of code

routes.MapPageRoute("Form", "Example", "~/Forms/Example.aspx");

you can actually do just that!

In this example I've created a folder called Forms inside of my MVC project and inside that project I've created a WebForms page named Example.aspx. To be able to access that page all I needed to do was to tell the routing thingy that I want the Example.aspx page to be available under /Example and that was it!

Now the question if we should go with WebForms or MVC is gone! You just use whatever suits your needs in the particular case you have to solve and you're done.

No comments:

About Me

I'm a passionate software developer with more than 15 years of experience in creating and maintaining several key software solutions. Wherever I go I spreads the word about new and updated means to satisfy the ever growing need for solving business problems.