Exploring Asp.net/MVC
What is Asp.net/MVC?
A Framework for building web applications, Based on Model-View-Controller Design Pattern.
ASP.NET MVC Parts
- Model
- Controller
- View
- Router
Model ( Data Object).
Controller (Control Application Actions).
View (Renders HTML).
Router (URL Mapping).
Why MVC?
- Complete control on HTML.
- Smooth Web 2.0 Development .
- SEO-friendly URLs.
- Easy Test Driven Development (TDD).
A main advantage of MVC is separation of concern. Separation of concern means we divide the application into Model, Controller and View.
We can easily maintain our application because of separation of concern.
In the same time we can split many developers work at a time. It will not affects one developer work to another developer work.
It supports TTD (test-driven development). We can create an application with unit test. We can write won test case.
Latest version of MVC Support default responsive web site and mobile templates.
What is a Model?
Models: C# Classes that Represent the data of the application Use validation logic to ensure business rule for that data
Model manages the applications data and enforces constraints on that model.
- Often accessed through persistent objects
- A model is a file of C# code and an associated data store
The file of C# code manages all access to the application’s data through objects.
Linq to SQL and Linq to XML create queries into these data stores
This can be direct More often it is done through objects that wrap db tables or XML files and have one public property for each attribute column of the table.
What is a View?
Views: Presentation file that our application uses to dynamically generate HTML Extension is .cshtml
Code is used just to support presentation and does no application processing.
The HTML is augmented by HTML Helpers, provided by Asp.Net MVC that provide shortcuts for commonly used HTML constructs.
Asp.Net MVC comes with jQuery (Javascript) libraries to support reacting to client actions and doing AJAX communication with the server.
What is a Controller?
Controller: C# Sharp classes handle request to application by user.
Get data from database or Object Specify View that return response to the Client
A controller is a C# file with controller classes that derive from the class Controller.
A controller defines some category of processing for the application.
Its methods define the processing details.
Routing to a controller is defined in the Global.Asax.cs file. Its default processing is usually what you need.
Asp.net web form VS Asp.net/MVC
-
ASP.NET Web Forms
Advantages:
▪ Fast Development.
▪ Windows Application Development Experience.
▪ Event Driven.
▪ View State.
▪ Web Controls.
Disadvantages:
▪ Hard to Control HTML.
▪ Unfriendly URLs.
▪ Single “Form” tag in single page.
-
ASP.NET MVC
Advantages:
▪ Model-View-Controller Design Pattern.
▪ Web Application Development Experience.
▪ Easy to control HTML.
▪ Friendly URLs (SEO).
Disadvantages:
▪ Stateless.
▪ More Development Time.
How to create ASP.net/MVC Project
- OPen Visual Studio and click on New Project
2. Select Visual C# and Asp.net Web Application
3. Select MVC
4 Ready to code
1 thought on “Exploring Asp.net/MVC”
Leave a Reply
You must be logged in to post a comment.
Good Points