Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • HTML Helper in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 212
    Comment on it

    An HTML Helper is just a method that returns a HTML string. The string can represent any type of content that you want

    Different types of HTML Helpers

    1 Inline Html Helpers

     @helper ListingItems(string[] items)
         {
         <ol>
         @foreach (string item in items)
         {
         <li>@item</li>
         }
         </ol>
         }
    
         <h3>Student Details:</h3>
    
         @ListingItems(new string[] { "DDUN", "Rishikesh", "Almora" })
    
         <h3>Student List:</h3>
    
         @ListingItems(new string[] { "Himanshu", "Mukesh", "Gopal" })
    

    2 Built-In Html Helpers HTML Element

    Example
    TextBox
    @Html.TextBox("Textbox1", "val")
    Output: <input id="Textbox1" name="Textbox1" type="text" value="val" />
    TextArea
    @Html.TextArea("Textarea1", "val", 5, 15, null)
    Output: <textarea cols="15" id="Textarea1" name="Textarea1" rows="5">val</textarea>
    Password
    @Html.Password("Password1", "val")
    Output: <input id="Password1" name="Password1" type="password" value="val" />
    Hidden Field
    @Html.Hidden("Hidden1", "val")
    Output: <input id="Hidden1" name="Hidden1" type="hidden" value="val" />
    CheckBox
    @Html.CheckBox("Checkbox1", false)
    Output: <input id="Checkbox1" name="Checkbox1" type="checkbox" value="true" /> <input name="myCheckbox" type="hidden" value="false" />
    RadioButton
    @Html.RadioButton("Radiobutton1", "val", true)
    Output: <input checked="checked" id="Radiobutton1" name="Radiobutton1" type="radio" value="val" />
    Drop-down list
    @Html.DropDownList (DropDownList1, new SelectList(new [] {"Male", "Female"}))
    Output: <select id="DropDownList1" name="DropDownList1"> <option>M</option> <option>F</option> </select>
    Multiple-select
    Html.ListBox(ListBox1, new MultiSelectList(new [] {"Cricket", "Chess"}))
    Output: <select id="ListBox1" multiple="multiple" name="ListBox1"> <option>Cricket</option> <option>Chess</option> </select>
    
    .net

 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: