ASP. NET 3.5 MVC Architecture and Practice Notes 6 htmlhelper Control Analysis

Source: Internet
Author: User
ArticleDirectory
    • Formextensions class
    • Inputextensions class
    • Linkextensions class
    • Renderpartialextensions class
    • Selectextensions class
    • Textareaextensions class
    • Validationextensions class
Formextensions class

The formextensions class is a static class and defines three types of extension methods: beginform, beginrouteform, and endform. In actual development, you can also use the using statement, you do not need to write the endform extension method.

Inputextensions class

The inputextensions class defines five types of extension methods: checkbox, hidden, password, radiobutton, textbox.

     <% = Html. beginform ("checkbox", "study ") %>      <  Fieldset  >         <  Legend  > Checkbox </  Legend  >          <% = Html. checkbox ("mycheckbox1", true, new {id = "checkbox1 "}) %>          <  Label   For = "Checkbox1"  > Xieti </ Label  >                  <% = Html. checkbox ("mycheckbox2", false, new {id = "mycheckbox2 "}) %>          <  Label   For = "Checkbox2"  > Heiti </  Label  >                  <  BR  /> <  BR  />          <  Input   Type = "Submit"   Value = "Submit"   />      </  Fieldset  >      <% Html. endform (); %> 

 

View the webpage after runningSource codeRight:

 < ! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >  <  Html   Xmlns = Http://www.w3.org/1999/xhtml"   >  <  Head  >  <  Title  > Testpage</  Title  >  </  Head  >  <  Body  >      <  Div  >      <  Form   Action = "/Study/Index"   Method ="Post"  > System. Web. MVC. html. mvcform <  Fieldset  >          <  Legend  > ?? Checkbox </  Legend  >          <  Input   Checked = "Checked"   ID ="Checkbox1"   Name = "Mycheckbox1"   Type = "Checkbox"   Value = "True"   />  <Input Name="Mycheckbox1" Type="Hidden" Value="False" />          < Label   For = "Checkbox1"  >  </  Label  >                  <  Input   ID = "Mycheckbox2"   Name = "Mycheckbox2"   Type = "Checkbox"   Value ="True"   />  <Input Name="Mycheckbox2" Type="Hidden" Value="False" />          <  Label   For = "Checkbox2"  >  </  Label  >                 <  BR  />  <  BR  />          <  Input   Type = "Submit"   Value = "Submit"   />      </  Fieldset  >      </ Form  >      </  Div  >  </  Body  >  </  Html  > 

For each checkbox control, MVC generates another hidden corresponding control.

<Input Name="Mycheckbox1" Type="Hidden" Value="False" /> <Input Name="Mycheckbox2" Type="Hidden" Value="False" />;

To check the status of the check box in the controller, you can use the followingCode:

PublicActionresult checkbox (formcollection ){BoolMycheckbox1 = formcollection [0]. Contains ("True");BoolMycheckbox2 = formcollection ["Checkbox2"]. Contains ("True"); Viewdata ["Mycheckbox1"] = Mycheckbox1; viewdata ["Mycheckbox2"] = Mycheckbox2;ReturnView ("Test");}

 

The password extension method mainly implements the text box for entering the password

Radiobutton mainly implements single-choice button controls

Textbox mainly implements single-line text boxes

 

Linkextensions class

Actionlink, routelink

Renderpartialextensions class

Display related user controls in the view

Selectextensions class

: Dropdownlist, ListBox

Textareaextensions class

: Set the textarea Control

Validationextensions class

: Implement control input verification validationmessage, validationsummary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.