Simple way to add, show asterisk after required field label in ASP.Net MVC

In this tutorial i am going to explain about Simple way to add, show asterisk after required field label in ASP.Net MVC. In my previous tutorial i have explained about

Implementation :

Now we will see the implementation of Simple way to add, show asterisk after required field label in ASP.Net MVC. Open visual studio and create a new project name it as ShowAsterik. And now right click on the model folder and add a new model/class called Employee.cs.

Add below code in Employee.cs

Now open the HomeController.cs and add a action method called Employee(). Right click on Employee action method and choose Add View option from context menu. Choose Create template and choose Employee model class and then click Add. Now the view will be generated.

Step 1 of Simple way to add, show asterisk after required field label in ASP.Net MVC

Below is the complete HomeController.cs code

Below is Employee.cshtml code.

Now if you run the action method employee in home controller and click the submit button you will see the below output.

Step 2 of Simple way to add, show asterisk after required field label in ASP.Net MVC

In the above output, after clicking Create button only user will know the required fields. So it is a good practice if we show asterisk(*) then user will understand that this are all mandatory fields. And also they will fill it before hitting the create button.

Simple way to add, show asterisk after required field label in ASP.Net MVC

Now to add, show asterisk after required field label in ASP.Net MVC, open the _Layout.html file in View/Shared folder and add the below jquery code.

So the modified _Layout.cshtml file will look like below.

Output:

Now if you run the application you can see the output of Simple way to add, show asterisk after required field label in ASP.Net MVC.

Output of Simple way to add, show asterisk after required field label in ASP.Net MVC

Now if you look into the above code it will display the asterisk(*)

Source Code:

Below you can download the source code of Simple way to add, show asterisk after required field label in ASP.Net MVC

Source code of Simple way to add, show asterisk after required field label in ASP.Net MVC

 

 

 

Conclusion:

Hope you learned about how to Simple way to add, show asterisk after required field label in ASP.Net MVC. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Comments

  1. Reply

  2. Reply

  3. Reply

  4. Reply

Leave a Reply

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