HTML Helper in ASP.NET Core Part 1- Session 28

HTML Helper in ASP.NET Core - Session28

During this session of ASP.NET Core tutorial, we are going to talk about HTML Helpers in ASP.NET Core and MVC and describe its benefits. Generally, HTML Helper is a Class that we can use its method in View Razor Pages and it renders HTML Tag in our Views. On the other hand, we can use HTML Helper method in our Views instead of regular HTML Tags. Thus, we can say, @html class has different methods to render HTML Tags with variety of overloaded that can help us to serve better Front End view. For instance, below codes are the same result.

What is HTML Helper in ASP.NET Core?

HTML Helper is a Class that includes several methods with different overloaded version that are used in Razor View Pages instead of HTML Tags.

What are the benefits of using HTML Helper in ASP.NET Core?

  • This class contains several overloaded methods same as IPostBackDataHandler that Pre-populate the values of html helpers(it works similar to as ViewStates)
  • It has built-in validation capacity for Text Box.
  • It has capacity of creating custom HTML Helper that can meet our requirement.
  • ViewData/ViewBag data can be bound to View elements easily.

Moreover, using HTML Helper instead of HTML Tag in Razor View Pages has several advantages.

  • @Html class contains several overloaded methods same as IPostBackDataHandler that Pre-populate the values of html helpers and it works similar to ViewStates
  • It has built-in validation capacity for Text Box and facilitate form validation.
  • HTML Helper has capacity of creating custom HTML Helper that can meet our requirement and able us to customize HTML Tags.
  • ViewData/ViewBag data can be bound to View elements more easily than the way that we use HTML Tags.

Using HTML Helper in MVC Views

In this session we cover four HTML Helper methods as shown below and will continue this topic in further sessions:

  • List()
  • TextBox()
  • TextArea()
  • DropDownList()

We can use @Html class methods in our Razor Page Views and call their required overloaded version to meet our purpose. Also, we can customize element attributes same as Style, Redaonly, Class and etc. as shown below and in this session Video.

Below piece of code reveals the way that we can use mentioned Helper in Razor View Page.

and the result of below code is as shown in below figure.

Result of the page that was created by HTML Helper

If you need more details, watch this session video. Also, for being updated about our coming sessions, follow us on Instagram, Facebook, Telegram or YouTube. Also you can have access to list of all sessions HERE.

You can download this Session Slides form HERE

0.00 avg. rating (0% score) - 0 votes

Tags

4 1 vote
Article Rating
guest

0 Comments
Inline Feedbacks
View all comments