HtmlHelper
FormExtensions static class
BeginForm, BeginRouteForm, and EndForm
FormMethod. Post has the highest priority
You can set the action parameter in multiple places, with the highest priority of htmlAttributes.
BeginRouteForm Extension Method for developers
;
Set the id and class values of the route value dictionary type
EndForm
<% Html. EndForm (); %>
Code
<% Using (Html. BeginForm ("index", "home", FormMethod. Post, new {action = "/Controller/actionName "}))
{%>
Form Content
<%}
%>
<% Using (Html. BeginForm ("index", "AfIndex ",
New RouteValueDictionary {"id", 123 }},
FormMethod. Post,
New RouteValueDictionary {"class", "cssName "}}
))
{%>
13 overload method
<%}
%>
<% Using (Html. BeginRouteForm (new {action = "action "}))
{%>
BeginRouteForm Extension Method for developers
<%}
%>
<% Html. EndForm (); %>
InputExtensions class
Five types: CheckBox, Hidden, Password, RadioButton, and TextBox
CheckBox
Code:
<% = Html. BeginForm ("CheckBox", "Home") %>
<Fieldset>
<Legend> set the font: </legend>
<% = Html. CheckBox ("MyCheckBox1", true, new {id = "checkBox1"}) %>
<Label for = "checkBox1"> </label>
<% = Html. CheckBox ("MyCheckBox2", false, new {id = "checkBox2"}) %>
<Label for = "checkBox1"> italic </label>
<Br/>
<Input type = "submit" value = "Submit"/>
</Fieldset>
<% Html. EndForm (); %>
<Asp: Content ID = "Content2" ContentPlaceHolderID = "MainContent" runat = "server">
<H2> CheckBox
<% = Html. TextBox ("t1", ViewData ["t1"]) %>
<% = Html. TextBox ("t2", ViewData ["t2"]) %>
</Asp: Content>
Public ActionResult CheckBox (FormCollection formcollection)
{
// Obtain the status value string of the check box control through the index
Bool myCheckBox1 = formcollection [0]. Contains ("true ");
// Obtain the status value string of the check box control through the key value
Bool myCheckBox2 = formcollection ["MyCheckBox2"]. Contains ("true ");
If (myCheckBox1)
ViewData ["t1"] = "1 Selected ";
Else
ViewData ["t1"] = "1 not selected ";
If (myCheckBox2)
ViewData ["t2"] = "2 selected ";
Else
ViewData ["t2"] = "2 not selected ";
Return View ();
}
Hidden
<% = Html. Hidden ("name", 123) %>
Password
<% = Html. Password ("password", 123) %>
RadioButton
<% Using (Html. BeginForm ("RadioButton", "Home "))
{%>
<Fieldset>
<Legend> set the font size </legend>
<% = Html. RadioButton ("MyRadioButton", "MyValue1", true, new {id = "MyRadioButton1"}) %>
<Label for = "MyRadioButton1">
10 # </label>
<% = Html. RadioButton ("MyRadioButton", "MyValue2", true, new {id = "MyRadioButton2"}) %>
<Label for = "MyRadioButton1">
20 # </label>
<Input class = "button" type = "submit" value = "submit"/>
</Fieldset>
<% }%>
<H2> RadioButton
<% = Html. TextBox ("t1", ViewData ["MyRadioButton"]) %>
Public ActionResult RadioButton (FormCollection formcollection)
{
String radioButtion1 = formcollection [0];
String radioButtion2 = formcollection ["MyRadioButton1"];
ViewData ["MyRadioButton"] = radioButtion1;
Return View ();
}
TextBox
<% = Html. TextBox ("Message") %>
<% = Html. TextBox ("myTextBox", null, new {size = 50}) %>
LinkExtensions class
ActionLink and RouteLink
ActionLink
The ActionLink extension method mainly implements a connection.
<% = Html. ActionLink ("actionlink", "About") %>
<% = Html. ActionLink ("actionlink", "About", "Home") %>
RouteLink
<% = Html. RouteLink ("routLink", "default", new {id = 100}) %>
RenderPartialExtensions class
RenderPartial this user control is mainly used to display the data table Categories
In ASP. net mvc when using the RenderPartial method, remember two points: first, in ASP. when the net mvc application is released to the production server, do not forget to disable the Debug mode (for ASP.. NET WebForm applications); second, minimize the number of calls to the RenderPartial method, such as traversing in UserControl.
From Idea-Cube. Net