In this recipe, you will learn how to create and manage namespaces in Razor
views by creating a _ViewImport
view to add all the necessary namespaces we need in our application views.
We create an empty web application with a controller and an index
view with the corresponding folders.
The goal of TagHelpers is to reduce the writing of the views using HTML tags and/or attributes interpreted by Razor
. They replace HTMLHelpers with the closest syntax of HTML, allowing integrators to work with MVC views more easily:
- First, let's add an
Insert
action method forGET
andPOST
inHomeController.cs
, and let's add a break point on theInsert
method ofPOST
:
- Next, let's add the
Insert
view with TagHelper code for an input to test TagHelpers:
- We can see the
asp-for
TagHelper added to the input text HTML element.
- Let's test the
POST
method, adding a value to the input:
- We click on the
Send
button to see what happened in theInsert
method...