Skip to main content

ASP.Net MVC Basics, Framework Request Flow, Why should we use ASP.Net MVC and Pre-requisite for MVC

Model View Controller (MVC): The Model-View-Controller (MVC) design pattern is an architectural design pattern for any standard development that separates the components of an application. This allows applications to handle very flexible and extensible and easy to handle.

The MVC model defines web applications with 3 logic layers: i.e. the business layer (Model logic), the display layer (View logic), and the input control (Controller logic)

ASP.NET MVC Framework has three main components

1.   Model:  It is the part of the application that handles the logic for the application data. Often model objects retrieve data (and store data) from a database. This manages the behavior and data of the application domain, responds to requests for information about its state from the view, and responds to instructions to change state. Basically MVC Model contains all application logic (business logic, validation logic, and data access logic), except pure view and controller logic.

2.   View: It is the parts of the application that handles the display of the data. Most often the views are created from the model data. This represents the presentation layer of the web application (i.e. aspx page).

3.   Controller: It is the part of the application that handles user interaction. Typically controllers read data from a view, control user input, and send input data to the model. User request comes through the controller to model and manipulate the records from it and then render the data using View to UI.


ASP.NET MVC Framework Request Flow:

·         Client requests the server for processing of controller and action.
·         ASP.NET Routing finds the route match by calling RouteCollection.GetRouteData
·         The MVC controller factory locates and creates the controller in CreateController
·         The ControllerActionInvoker determines which action to run in InvokeAction
·         Controller processes client’s request and creates a data Model.
·         Model is passed to view for transformation.
·         View transforms Model into appropriate UI to send it back to the client.
·         Response (UI) is rendered to the client’s browser.

Why should we use ASP.net MVC?

·         Provides clean separation of concerns (SoC). The code organization within MVC is very clean, organized, and granular, making it easier for a web application to scale in terms of functionality. Promotes great design from a development standpoint.
·         MVC enables Test Driven Development (TDD). With MVC, you can more easily create tests for the web side of things. An additional layer of testing will provide yet another layer of defense against unexpected behavior.
·         MVC is great for Search Engine Optimization as you control the URL (though now you can achieve this in ASP.NET 4 as well).
·         Clean View Markup (no additional HTML emitted) and MVC enable full control over the rendered HTML.
·         SEO-friendly URL by design (though now this is possible in ASP.NET 4 as well)
·         No ViewState (this may seem a bit of moving backward to some), but overall a good design decision.
·         No ViewState and PostBack events, which eventually makes MVC faster in performance.
·         MVC follows the design of the stateless nature of the web.
·         Rich UI support (possible through client-side JS libraries like jQuery UI and others).
·         More power validation with DataAnnotations and jQuery.
·         Easy integration with JavaScript frameworks.
·         MVC is much easier to create very complex websites with a minimum of code.
·         MVC is not a replacement if ASP.NET Web Form-based development. This seat on the top of ASP.NET Development.

Pre-requisite for MVC: So we have learned some basic details about MVC, and now wanted to work on MVC application, so the question that comes to mind is MVC work on our existing platform or whether we need to enhance our development environment.

Here is the answer: To create a MVC application you need,

·         Visual Web Developer 2012 (If you have Windows 7 or Windows 8)

·         Visual Web Developer 2010 or the free Visual Web Developer 2010 Express. These include ASP.NET MVC 2 template by default. (If you have Windows Vista or XP)

·         Visual Studio 2008 SP1 (any edition) or the free Visual Web Developer 2008 Express with SP1. These do not include ASP.NET MVC 2 by default; you must also download and install ASP.NET MVC 2 from http://www.asp.net/mvc/.

Comments

  1. Your information about asp.net frame works is really interesting and innovative. Also I want you to share latest updates about this frameworks. Can you update it in your website? Thanks for sharing
    Dot net training institute in Chennai

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Keep up the good work; I read few posts on this website, including I consider that your blog is fascinating and has sets of the fantastic piece of information




    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery





    ReplyDelete

Post a Comment

Popular posts from this blog

Error 405 : ASP.NET Core Web API PUT and DELETE Methods not allowed

Recently, while working with .Net core API I came across the issue of “Error 405 — Methods not Allowed” After some research, I found out that both GET and POST requests working fine but neither PUT nor DELETE requests working. Another thing is that the PUT and DELETE request was also working fine on my local machine but failed when we host on our Azure server. When I explored the issue on the web it led me to the conclusion that WebDAVModule seems to set PUT and DELETE request methods disabled by default and due to that PUT and DELETE throw 405 errors. To make the PUT and DELETE requests work, we need to override the WebDAVModule setting in web.config file by adding the below settings under “ system.webServer ”. < system.webServer >   < modules runAllManagedModulesForAllRequests = " false " >     < remove name = " WebDAVModule " />   </ modules > </ system.webServer > There may be 2 web.config files in y...

C#: Merging Excel cells with NPOI HSSFWorkbook

In this post we’ll see how to merge the two or more cell with each other while creating the excel sheet using NPOI . Mentioned below is code to merge multiple cells, in this example we are merging first cell to fifth cell of first row (you can adjust row or cell range by passing particular parameters in CellRangeAddress). //Created new Workbook var hwb = new NPOI.HSSF.UserModel. HSSFWorkbook (); //Create worksheet with name. var sheet = hwb.CreateSheet( "new sheet" ); //Create row and cell. var row = sheet.CreateRow(0); var cell = row.CreateCell(0); ; //Set text inside cell cell.SetCellValue( "This is Merged cell" ); cell.CellStyle.WrapText = true ; //define cell range address // parameters: -> first row to last and first cell to last cell var cra = new NPOI.SS.Util. CellRangeAddress (0, 0, 0, 4); //Add merged region to sheet. sheet.AddMergedRegion(cra); Hope this solution helps you J

How to set Swagger as the default start page for API hosted on the Azure web app?

I created an Asp.Net Core 2.x Web API and configured Swagger on it, below is the code added in Configure method under Startup.cs file, for full swagger configuration, check here //Add swagger configuration app.UseSwagger(); app.UseSwaggerUI(c => {     c.SwaggerEndpoint( "../swagger/v1/swagger.json" , "Test API V1" ); }); On my local machine when I run the API it is automatically redirected to the Swagger page. However, when I hosted this API as an Azure web app it is not redirecting directly to the Swagger and to access the swagger, I had to append /swagger in the URL, for example, https://testapi.azurewebsites.net/swagger/ Solution: Set RoutePrefix to string.Empty under app.UseSwaggerUI like below: app.UseSwaggerUI(c => {     c.SwaggerEndpoint( "../swagger/v1/swagger.json" , "Test API V1" );      c.RoutePrefix = string .Empty; // Set Swagger UI at apps root }); And that’s it, now when you b...