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 patterns for any standard development that separates the components of an application. This allows application 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 having 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 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 client.
·         Response (UI) is rendered to client’s browser.

Why should we use 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 enables the 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 follow the design of 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 question comes in mind is MVC work on our existing platform or 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

Popular posts from this blog

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

Read and parse a CSV file into an array of rows and columns in C#

The following PopulateCsvIntoArraymethod used to read the CSV file into a two-dimensional array of strings.
I have included explanation of method lines, wherever needed. ///<summary> /// Populate the CSV file into an array, /// We assume that every line has the same number of fields and there may be blank lines. ///</summary> ///<returns></returns> privatestring[,] PopulateCsvIntoArray() { // Get path of CSV file. var path = Server.MapPath("~/Folder_Name/testfile.csv"); // Get the file's text using ReadAllText method. string fileData = System.IO.File.ReadAllText(path);
// Split CSV data into lines.     fileData = fileData.Replace('\n', '\r'); string[] lines = fileData.Split(newchar[] { '\r' }, StringSplitOptions.RemoveEmptyEntries);
// Get rows and columns counts. int totalRows = lines.Length;

Calculate Sum and average of two or more Textbox values using JQuery

We can calculate sum and average of values entered in textboxes with the help of small piece of jQuery code.
First of all let’s create a HTML form where we’ll ask user to enter marks in each subject, under body section add following HTML:
<tableclass="demo-table"> <trclass="label"> <tdcolspan="2">Please enter marks(0-99):</td> </tr> <tr> <td>English</td> <td> <inputtype="text"class="txtMarks"name="txtMarks"