Focusing on the rebirth of ASP. NET.3.5.MVC architecture: HtmlHelper (1)

Source: Internet
Author: User
Tags actionlink

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

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.