Introduction To MVC Architecure In ASP.Net With Example

The Model-View-Controller (MVC) pattern was introduced in 1970s. MVC is a “design pattern” That isolate “Domain Logic” (The application logic) from the user interface (Input and Presentation) permitting independent development, testing and Maintenance of Each.

It categories Application into three main aspects: Model, View and Controller. Moreover MVC is separation of concerns. Means it separates data access logic and business logic from the User Interface.
ASP.Net MVC did not replace old ASP.net Web forms development, but ASP.Net MVC provided alternate way to develop application using Design Pattern. it is one of the new development models.
Introduction To MVC Architecure In ASP.Net With Example

Model : It retrieve the application data from Database and it also contain business logic to change the state mention by controller.it is plain .net class

Controller:

Controllers are just a class that implements Icontrollers and it derived from provided controller class. It prepares data and render on the view. Controllers are invoked via routing mechanisms.MVC preferred controllers action methods should be public. As a developer we know public methods are not safe for security purpose, we can use” [Non Action]” attributes to prevent public access. Each action method mapped to one view page.

MVC Action Result in Controller

Note:- In above figure, ActionResult is a Base class for all action methods, so you can use ActionResult to   return any Action Helper Methods.

Controllers Core Action Functionality  (Action Methods)

  • ViewResult- If you want to show a view.
  • ContentResult-Directly returns Content (instead of returning string use ContentResult).
  • FileResult-To returns a file.
  • RedirectResult-To redirects a new URL.
  • RedirectToRouteResult- Redirects to Route.
  • EmptyResult-Returns a null object (instead of Void).
  • JsonResult-Used to Send Json formatted-content to response.
  • JavaScriptResult- sends java script content to response.

View:

It takes data from Controller and display Physical form that user can View (Browser). Browser requests are not mapped to view page but it mapped to action methods.

Advantages of MVC

  • Better Separation of concerned.
  • Testability
  • Model Binder Plays very important role.
  • No ViewState anymore.
  • Inbuilt efficient Search Engine Optimization (SEO).
  • Complete control over HTML output.
  • Lightweight No server Controls it saves conversion time to HTML.
  • Easier Integration with JavaScript/JQuery.

In this post i have given the introduction for Model View Controller in ASP .net . In coming post i will explain MVC step by step using code snippets . Please give your feedback and suggestion in the comments. Also please like our facebook page  and also follow us on Twitter for updates.

9
SHARES

Rahul Kumar

Rahul is a ASP.Net Developer and having 2 years of Experience in G2C and e- Governance based Application development.

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *