articles

Home / DeveloperSection / Articles / MVC (Model View Controller)

MVC (Model View Controller)

Vijay Shukla7285 06-Nov-2012

MVC is a Framework which is use for building a web application with the facilitate of MVC Design. It’s 100% extensible.

Here are three patterns for implemented and design for MVC Application.

1.    Model:  The Model pattern will handled the logic of the application data. A model is easy to get both controller and view. Pass the data from controller to view by the Model.

2.   View: The view pattern exhibit the user interface of an application. This interface shaped with the Model data.

3.   Controller: The controllers will interaction with the user request. Controller watch out the whole execution of request. It’s got the request from the web server and checks the data necessities.

MVC (Model View Controller)

Mechanism of MVC
Advantage of ASP.net MVC

1.       One of the biggest problems in ASP.NET is HTML size of controls and view state.

2.       There is no view state and post back event concept in MVC framework.

3.       Easy integration with java script framework.

4.       Enable the full control over the rendered HTML.  

5.       That makes applications load faster and some of the processing can be done in web browsers.

6.      It’s execution faster too in client site as well as server site.

Difference between ASP.net MVC and ASP.net 

Sr.

ASP.net

 

ASP.net MVC

1

View is called before controller.

 

 

Controller renders view based on action as a result of the user interaction on the User Interface.

2

It’s easily work for a small team where focus is on RAD (Rapid Application Development).

 

 

It’s very well work for big projects where focus on testability and maintainability.

 

3

ASP.net manages by using view state and server based controls.

 

ASP.net MVC doesn’t maintain state information by using view state.

4

The View State also increases your page size

 

Usually size of page is small.

5

ASP.net is an event driven programming like a windows application.

 

ASP.net MVC isn’t an event driven programming.

6

It can be reduce your time with the help of drag and drop facilities.

 

You lose the drag and drop feature.

Create Asp.net MVC 3 Application using C#                
Create MVC Application in Visual Studio 2010:

1.      Open Visual Studio 2010.
2.      Click on New Project or Go to File  Menu and select the New >> Project.(Ctrl+Shift+N)

3.      New Project Dialog Box will appear.

4.      You must select the Visual C# in Left pane on the New Project Dialog Box.

5.      Select the ASP.net MVC3 Web Application.

6.      Give the Name of under the naming convention and you can also change the
location of project through the Browse. Here I’m using name ‘MyFirstMVCApp’
.MVC (Model View Controller)
7.      Then Press OK button.

8.      Next step is. Select a project type from the project template. We can select singly Empty or Internet Application from project template.

9.      Next step is. Select View Engine from Dropdown list. Here are two View Engine provided by ASP.NET MVC i.e. ASPX and Razor.

10.  I have selected a Razor view for my application.
Difference between Razor and ASPX

Razor View engine is introduced in MVC 3. Razor View has ‘.cshtml’ file extension in C# and ‘vbhtml’ in Visual Basic. In the Razor View code writes down in @ symbol. Razor has a big advantage in simplicity and readability. RazorPages are complied with DLLs. So once you’ve hit the page, it’s just as fast as any other page.Razor minimizes the number of characters and keystroke required in a file, and enables a fast coding workflow

Example: @HTML.somthing

Whereas ASPX View engine with have ‘.aspx’ file extension for both C# as well as Visual Basic. In the ASPX View we have write down code in scriptlet tag< %%>. ASPX is a very simple language to parse. 

Example: <%HTML.something %>

MVC (Model View Controller)

11.  Then Press OK  button.

12.  Open Solution Explorer (Ctrl+Alt+L) right click on Controller folder and add a new controller.


MVC (Model View Controller)

13.  After Selection Controller… Controller Dialog Box will be appearing.


MVC (Model View Controller)

14.  Press Ok  button to Add Controller.


MVC (Model View Controller)

15.  This Screen will appear after press OK button.


16.  Right Click on ActionResult and select Add View… .   


MVC (Model View Controller)

  17.  To add a view with name of Index and select view Engine is Razor (CSHTML).


MVC (Model View Controller)

18.  Press Add Button.

19.  After Press Add button this screen will be appear.

MVC (Model View Controller)

20.  Pop back again HomeController.cs and type this code give the message for Index view in Index().

MVC (Model View Controller)

21.  Pop back again in Index.cshtml.

MVC (Model View Controller)

 Now press F5 for Debug application and show the output on your Web Browser Welcome to ASP.NET MVC!

 

MVC (Model View Controller)


Updated 07-Sep-2019

Leave Comment

Comments

Liked By