ASP.Net MVC is a pattern which is used to split the application's implementation logic into three components i.e. models, views, and controllers.
The Model It represents the application data domain. In other words applications business logic is contained within the model and is responsible for maintaining data.
Often model objects retrieve data (and store data) from a database.
The View is the part of the application that handles the display of the data.
It is user interface to render domain data.
The Controller is the part of the application that handles user interaction.
Below are some of the features supported in C# -
Layout pages, can define sections, which can then be overriden by specific views making use of the layout. Defining and overriding sections is optional.
The base type of all these result types is ActionResult.
1. ViewResult (View): This return type is used to return a webpage from an action method.
2. PartialviewResult (Partialview): This return type is used to send a part of a view which will be rendered in another view.
3. RedirectResult (Redirect): This return type is used to redirect to any other controller and action method depending on the URL.
4. RedirectToRouteResult (RedirectToAction, RedirectToRoute): This return type is used when we want to redirect to any other action method.
5. ContentResult (Content): This return type is used to return HTTP content type like text/plain as the result of the action.
6. jsonResult (json): This return type is used when we want to return a JSON message.
7. javascriptResult (javascript): This return type is used to return JavaScript code that will run in browser.
8. FileResult (File): This return type is used to send binary output in response.
9. EmptyResult: This return type is used to return nothing (void) in the result.
Razor syntax are easy to learn and much clean than Web Form syntax. Razor uses @ symbol to make the code like as:
Filters allow us to add pre-action and post-action behaviors from action, for achieving this functionality ASP.NET MVC provides a feature called Filters.
ASP.NET MVC supports following types of filters:
This page is used to make sure common layout page will be used for multiple views. Code written in this file will be executed first when application is being loaded.
This method is used to render the specified partial view as an HTML string. This method does not depend on any action methods. We can use this like below :-
"RouteConfig.cs" holds the routing configuration for MVC. RouteConfig will be initialized on Application_Start event registered in Global.asax.
In an ASP.NET web application that does not make use of routing, an incoming browser request should map to a physical file. If the file does not exist, we get page not found error.
An ASP.NET web application that does make use of routing, makes use of URLs that do not have to map to specific files in a Web site. Because the URL does not have to map to a file, you can use URLs that are descriptive of the user's action and therefore are more easily understood by users.
What are the 3 things that are needed to specify a route ?routes.MapRoute(
"View", // Route name
"View/ViewCustomer/{id}", // URL with parameters
new { controller = "Customer", action = "DisplayCustomer",
id = UrlParameter.Optional }); // Parameter defaults
ASP.NET Web API supports this type routing. This is introduced in ASP.Net MVC5. In this type of routing, attributes are being used to define the routes. This type of routing gives more control over classic URI Routing. Attribute Routing can be defined at controller level or at Action level like :-
[Route("{action = CourseList}")] - Controller Level
[Route("Students/{CourseListId:int:min(10)}")] - Action Level
Html.TextBox("SubjectCode")
Html.TextBoxFor(m => m.SubjectCode)
In the same way we have for other HTML controls like for checkbox we have "Html.CheckBox" and "Html.CheckBoxFor".
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery-3.1.1.min.js",
"~/Scripts/jquery.validate.min.js",
"~/Scripts/jquery.validate.unobtrusive.min.js"));
AJAX Helpers are used to create AJAX enabled elements like as Ajax enabled forms and links which performs the request asynchronously and these are extension methods of AJAXHelper class which exists in namespace - System.Web.ASP.Net MVC.
Partial view in MVC renders a portion of view content. It is helpful in reducing code duplication. In simple terms, partial view allows to render a view within the parent view.
Scaffolding in ASP.NET MVC is used to generate the Controllers,Model and Views for create, read, update, and delete (CRUD) functionality in an application. The scaffolding will be knowing the naming conventions used for models and controllers and views.
Below are the types of scaffoldings –
Area is used to store the details of the modules of our project. This is really helpful for big applications, where controllers, views and models are all in main controller, view and model folders and it is very difficult to manage.
REST is an architectural style which uses HTTP protocol methods like GET, POST, PUT, and DELETE to access the data. MVC works in this style. In MVC 4 there is a support for Web API which uses to build the service using HTTP verbs.
Below are the options in AJAX helpers –