HTML helper classes

Working with HTML helpers:

HTML helpers are used to under the HTML controls within the MVC views.

2MVC will support following HTML helpers

              Name                                        Syntax

  1. Label                2      label (string text)
  2. Text box          2      textbox (string name, object value)
  3. Password       2    password (string name, object value)
  4. Radio button 2 Radiobutton (string name, object value, bool checked)
  5. Check box     2  checkbox (string name, bool checked)
  6. Drop down list box2Dropdown list (string nmae)
  7. List box          2listbox (string name)
  8. Render action  2Renderaction (string actionname, string control name)
  9. Link button     2action link (string linktext, string action name, string controller name)
  10. Text area        2text area (string name)
  11. HTML encoder  2encode(string text/object value)
  12. Validate          2validate (string model name)
  13. Validate message 2validate message (string model name, string message)
  14. Form                 2Begin form ()

                                3

HTML.End form ()

Working with HTML helper class:

Code for dropdown list creating and list box

Go to sample view write the following code

<%= HTML.label(“select qualification”)%>

<%=HTML.DropDownList(“CB1”)%><br%>

<%=HTML.label(“select skill set”)%>

<%=HTML.listbox(“LB”)>

Go to home controller .cs                          

       ↓

Interested in ASP.net Training? Enroll now for FREE demo on ASP.net Training.

In sample action method write the following code

To add the list of elements to the combo box and list box

Public action result sample ()

{

List <string> L1=new list<string> ()}

L1.add (“USC”);

L1.add (“10+2”);

L1.add (“Degree”);

List <string> L2=new list <string> ();

L2.add (“C#.net”);

L2.add (“ASP.net”);

L2.add (“WCF”);

L2.add (“AJAX”);

View data [“cb1”] = new select list (L1);

View data [“cb2”] = new select list (L2);

Return view ();

}

For indepth understanding click on