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