Hi Friends,
Today I will tell you about using the custom helper in mvc. We can create our own helper extension.We have multiple extensions as shown below in figure:-
As these above extensions are predefined. But we can define our own extension which will be used in all razor views.
Below are the steps:-
1. Firstly create a class and put a proper name i am using the name "Helper" and I am creating a label as shown below in the code:-
namespace CustomHelper
{
public static class Helper
{
public static IHtmlString CustomHelper(this HtmlHelper htmlHelper)
{
return new HtmlString("<label>This is Sample Custom Helper</label>");
}
}
}
2. Now add the namespace in the web.config of the Views where all namespace are added. Put there
<add namespace="CustomHelper" />
Where "CustomHelper" is the name of the namespace that i am using.
3. Now we can use our helper in all views as shown below in the figure.
Have any query do mention in comments.
Thanks
Happy Coding!!
0 Comment(s)