Converting classic ASP and ASP.Net web form to MVC

MVC and ASP.Net Development

MVC and ASP.Net Development

When it comes to application development within the Microsoft Stack, there are two popular frameworks: Asp.Net MVC and Web Forms. was developed a few years ago as a replacement to Classic ASP, and it featured Web Forms.

However, while Web Forms was acceptable for smaller projects, proved to be difficult to scale for larger applications. Specific pages and code tend to be tightly tied together and the heavy reliance on the server to handle events, control rendering also adds to reduced performance. MVC help alleviate these issues by implementing the “Model View Controller” pattern. With the separation of the layers, it helps development by allowing applications to be more expandable, quicker to develop and more organized long term when it comes to maintenance.

One of the first steps when converting a non MVC site to MVC site, is to define your Model, View, Controller architecture.

Model Layer

Starting with the Model layer, this begins with identifying the data elements used by the application. These data objects would be retrieved by the controller layer and used in order to generate the view which is returned back to the user’s browser.  During this step additional layers to work with the database are created. This approach allows more flexibility in case of changes in the database. In general this can be done by analyzing the existing database and in most cases each table can be represented as a data model object.

Controller Layer

The Controller layer, is responsible for managing user interactions with the application, by responding to user request and returning the appropriate updates are made to the user’s view (browser). At this step we would analyze all the pages of the previous application and determine all actions, events that are required. This includes preparing data to be displayed on page load, responding to button clicks whether saving data, page navigation etc.

View/Presentation Layer

Through the separation of the code behind on each page, the View layer is now more free to be coded with more plain HTML code. This can be done through the Razor markup which presents a more html like way of embedding code or even updating the view to use a more front-end framework like Angular. During this step, web form pages will be stripped of the server side control code and focus on updating to contain only front end UI view code. This results in view pages that are easier to update  based on designs from Graphic Designers who may not be as familiar with working with or have direct access to the web form code.

Converting to the MVC pattern arranges the code in more separated and organized fashion. However, additional steps can be made to improve the sites performance, and overall organization even more. Through the use of Javascript front-end frameworks like Angular and utilized MVC Web.API framework. Using MVC Web.api, controllers are now designed as more HTTP service. Allowing more flexibility in responding to user action and events.  This approach allows the view to be more independent, allowing the website to be more accessible whether through web or mobile. With these steps we can help upgrade existing site to be more expandable, quicker and responsive to the clients needs.



/ relevant articles

Get Free Consultation

share your thoughts with us and our experts will help you achieve your goal.