What is Razor?
Razor is a markup syntax that lets you embed server-based code (Visual Basic and C#) into web pages.
Server-based code can create dynamic web content on the fly, while a web page is written to the browser. When a web page is called, the server executes the server-based code inside the page before it returns the page to the browser. By running on the server, the code can perform complex tasks, like accessing databases.
We can add validations to our application by adding Data Annotations to our model classes. Data Annotations allow us to describe the rules we want applied to our model properties, and ASP.NET MVC will take care of enforcing them and displaying appropriate messages to users.
The anti-forgery token can be used to help protect your application against cross-site request forgery. To use this feature, call the AntiForgeryToken method from a form and add the ValidateAntiForgeryTokenAttribute attribute to the action method that you want to protect.
Generates a hidden form field (anti-forgery token) that is validated when the form is submitted.
CRUD Operation refers to classic (create, read, update, delete) operations as it pertains to data.
In ASP MVC context there are several ways to CRUD your data using Models and subsequently views, Controllers.
One simple way is to make use of the scaffolding feature provided by the Visual studio templates and customize to your needs.
Please keep in mind that CRUD is very broadly defined and it has many variations to suit your requirements. For e.g. Database first, Entity first etc.
HTML helpers are methods used to render HTML elements in a view. They are part of the
There are different types of HTML helpers:
Standard HTML Helpers: They are used to render normal HTML elements, e.g.
Strongly Typed HTML Helpers: These helpers render HTML elements based on model properties, e.g.
Custom HTML Helpers: The user can create custom helper method which returns
Routing is how ASP.NET MVC matches a URI to an action. Routing module is responsible for mapping incoming browser requests to particular MVC controller actions.
MVC 5 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web application.
ViewData, ViewBag, TempData
ViewBag are used to transfer data from controller to view.
ViewData is nothing but a dictionary of objects and it is accessible by string as key.
ViewBag is very similar to ViewData. ViewBag is a dynamic property. ViewBag is just a wrapper around the ViewData.
TempData keeps data for the time of HTTP Request, which means that it holds data between two consecutive requests. TempData helps us to transfer data between controllers or between actions. Internally uses session.
Display and Editor templates
When dealing with objects in an MVC app, if any object should be shown in multiple places with the same format, we'd need some kind of standardized layout. ASP.NET MVC has made this kind of standardization easy to do with the inclusion of display and editor templates. In short, display and editor templates are used to standardize the layout shown to the user when editing or displaying certain types or classes.