Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Custom Helper in MVC Razor

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 258
    Comment on it

    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!!

    Custom Helper in MVC Razor

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: