
In this article, you will learn the following points about HTML Helpers in MVC 5.
- What is HTML Helper in ASP.NET MVC 5?
- Type of HTML Helpers?
- What is Inline HTML Helper in MVC 5?
- How to use Inline HTML helpers on View?.
- Example of Inline HTML helpers?
- How to reuse same Inline Html Helper method in different Div?
- Interview Questions
What is HTML Helper in ASP.NET MVC 5?
- HTML Helpers are methods that return a string.
- Helper class can create HTML controls programmatically. HTML Helpers are used in View to render HTML content.
- It is not mandatory to use HTML Helper classes for building an ASP.NET MVC application.
- We can build an ASP.NET MVC application without using them, but HTML Helpers helps in the rapid development of a view.
- HTML Helpers are more lightweight as compared to ASP.NET Web Form controls as they do not use ViewState and do not have event models.
- MVC has built-in Helpers methods
- We can create custom HTML helpers.
Type of HTML Helpers?
HTML Helpers are categorized into three types,
- Inline HTML helpers
- Built-in HTML helpers
- Standard HTML Helpers
-
Strongly Typed HTML helpers
-
Templated HTML helpers
- Custom HTML helpers
In this article, we will understand about Inline HTML Helper in MVC 5. We will discuss the other types in the next subsequent article of this series.
What is Inline HTML Helper in MVC 5?
- Inline HTML Helper is used to create a reusable Helper method by using the Razor @helper tag.
- Inline helpers can be reused only on the same view.
- We can not use Inline helper to the different view Pages.
- We can create our own Inline helper method based on our requirements.
Advantages of using Inline HTML Helper in MVC 5
- It is reusable on the same view.
- It reduces the code repetition
- It is simple to create and easy to use.
- It is easy to customization the method based on the requirement.
Syntax of Inline Html Helper
@helper HelperName(Parameters list..)
{
// code.....
}
Example of Inline HTML helpers
To understand the Inline HTML Helper, we need to create an application in Visual Studio 2015/2017/above.
In previous tutorials, we have understood about create the project in ASP.NET MVC 5 using Visual Studio, how to add a controller and Add View in MVC 5, and steps to create an application for ASP.NET MVC 5 using Visual Studio.
After creating the application, we need to create one Index view and add the following code.
Example 1
We can create inline HTML Helper method having integer parameter.
- @helper AddHelper(int a, int b)
- {
- <label>Addition of two No = @(a + b)</label>
- }
This is how we use inline HTML Helper method in View.
- <div style="background-color:azure;">
- <label> @AddHelper(100, 200)</label>
- </div>
Output 1

Example 2
We can create inline HTML Helper method having string parameter.
- @helper PrintHelper(string message)
- {
- <label>@message</label>
- }
This is how to use inline HTML Helper method in View.
- <div style="background-color:azure;">
- <label> @PrintHelper("Welcome to Learning ASP.NET MVC 5 Tutorials Step by Step.")</label>
- </div>




Avinash kumarPosted Nov 24, 2022, 1:45 AM
Nice one thank you so much
Sourav Kumar DasPosted Sep 30, 2019, 11:28 PM
Nice Article Sir.