If you’re a corporate C# Software Developer maybe you haven’t had enough time at work to “upgrade” existing ASP.Net AJAX project to ASP.Net MVC. I recall on the corporate profile because it’s very different if you’re a hobbyist willing to spend a couple of hours in a new project or if you’re part of a company with a product made of millions of lines of code deployed in thousands of clients. Don’t take me wrong, all of us are Software Developers by hearth but, all of we work in different conditions.

So, probably you have been thinking that although that big application is selling well over years is too big and too ugly to give it a try on a new technology. But for these couple of technologies is another story, AJAXand MVC are based on ASP.Net so they can co-exit. You can maintain an old application in AJAXwhile adding new features in MVC razor, if you want. There is an old (but still relevant) good post from Scott Hanselman about it.

You may be wondering why mixing up is a good advice; the answer is reusing. Don’t throw away tested lines of code, reduce the risk instead, start only the new things in the new technology without shutting down all completely at the same time.

Another good reason can be new projects without User Experience’s guidance. As you may thinkAJAXUI-controls are well ahead of the current offering of MVC controls, so it may help if you do the general layout in AJAX (using candy eye graphical designs) and each page in MVC Razor.

I assume that you already read the suggested link, so I just want to comment that you won’t be able to reuse the Master page and that maybe some MVC Razor pages will need a Web Form wrapper in order to reuse your current investment or to quickly implement a good UI design.

Imagine you have a nice UI design based done in Web Forms, so you should reference your new MVC Razor pages with the Controllers Action methods. In the next code snippet the ContentUrl property is referencing a MVC Controller which will return a Razor view:

<telerik:RadSplitter runat="server" ID="RadSplitter2" Width="100%" BorderSize="0"

BorderStyle="None" PanesBorderSize="0" Height="100%" Orientation="Horizontal">

<telerik:RadPane ID="RadPane5" runat="server" ContentUrl="../Page/Action" Height="100%" >

</telerik:RadPane>

</telerik:RadSplitter>

Reusing is good but don’t reuse bad habits. If you opt for this approach (having a hybrid application) then refactor your code to enable a Controller like Page-Code interaction, don’t place code in the ASPX files and try to make your classes behave stateless; stateless in ASP.Net MVC also means not overusing the TempData, ViewData or ViewBag objects (here a post from Rachel Appel on how use them). Avoid writing new views as follows:

@(Html.Telerik().Grid(Model)

.Name("Grid")

.Columns(columns =>

{

columns.Bound(o => o.OrderID).Width(100);

columns.Bound(o => o.ContactName).Width(200);

columns.Bound(o => o.ShipAddress);

columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(120);

})

.DataBinding(dataBinding =>

{

dataBinding.Server().Select("FirstLook", "Grid", new {ajax= ViewData["ajax"] });

dataBinding.Ajax().Select("_FirstLook", "Grid").Enabled((bool)ViewData["ajax"]);

})

.Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))

.Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))

.Pageable(paging => paging.Enabled((bool)ViewData["paging"]))

.Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))

.Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))

.Footer((bool)ViewData["showFooter"]))

By moving to ASP.Net MVC you will decouple your code from your views, you will integrate smoothly your Views with modern UI java script frameworks and third party libraries and you will be able in a near time to fully leverage ASP.Net MVC.

Cheers,

Javier Andrés Cáceres Alvis

Microsoft Most Valuable Professional – MVP
Intel Black Belt Software Developer