Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • HTML helpers in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 426
    Comment on it

     Here you will learn about HTML Helpers. HTML helper is just a method which generates elements. This element represents the content which we want to add in HTML.


    Below is the format of using HTML helpers in ASP.NET MVC framework:-


    Html Helper HTML Control Example
    Html.TextBox Textbox

    @Html.TextBox("Textbox1", "val") 

    Output: <input id="Textbox1" name="Textbox1" type="text" value="val" />

    Html.TextArea Textarea

    @Html.TextArea("Textarea1", "val", 5, 15, null) 

    Output: <textarea cols="15" id="Textarea1" name="Textarea1" rows="5">val</textarea>

    Password Password textbox

    @Html.Password("Password1", "val") 

    Output: <input id="Password1" name="Password1" type="password" value="val" />

    Html.Hidden Hidden Field

    @Html.Hidden("Hidden1", "val") 

    Output: <input id="Hidden1" name="Hidden1" type="hidden" value="val" />

    Html.CheckBox CheckBox

    @Html.CheckBox("Checkbox1", false) 

    Output: <input id="Checkbox1" name="Checkbox1" type="checkbox" value="true" /> <input name="myCheckbox" type="hidden" value="false" />


    There are many more examples of HTML helper which are used in ASP.NET.

    There are 3 type of HTML helpers:-

    • Inline HTML Helper- The syntax of inline helper is @helper. It makes the code more readable.                                  
    • Built-In HTML Helper- This is extension method in HTML Helper class. It provide the most common type of HTML element. For e.g- Textarea, checkbox, password etc.
    • Custom HTML Helper- This method is created by using extension method or by creating static method.

 0 Comment(s)

Sign In

Sign up using

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: