@ HTML helper simple description, record some basic @ HTML helper corresponding to HTML, @ HTML basically contains the Form Control in HTML and common html
In @ HTML, The for mainly targets HTML types with strong types.
Used to describe the tag in @ HTML, and define the student object for help description,
Public class student {// <summary> /// name // </Summary> // [displayname ("name")] public string name {Get; set ;}/// <summary >/// age /// </Summary> Public int age {Get; Set ;}}
Define @ model student on the cshtml page
Label label, which is implemented in the labelextensions class
1. @ html. Label ()
Returns the attribute name of an HTML label element and an attribute represented by a specified expression.
Parameter: string expression, string labeltext
Expression: the attribute to be displayed.
Labeltext: display text
Example:
@ HTML. label ("weight") Output: <label for = "weight"> weight </label> @ HTML. label ("name", "name") Output: <label for = "name"> name </label>
2. @ html. labelfor ()
Similar to @ html. Label (), but mainly for strong types
Example:
@ HTML. labelfor (model => mode. name) Output: <label for = "name"> name </label> @ HTML. labelfor (model => mode. name, "name") Output: <label for = "name"> name </label> if you add the [displayname ("name")] feature (reference system. componentmodel;): <label for = "name"> name </label> is used to display Chinese characters.
3. @ html. labelformodel ()
Example: @ html. labelformodel ("name") Output: <label for = ""> name </label>
Editor tag, indicating the Input Form Control in the application, which is implemented in editorextensions
1. @ html. Editor ()
Returns the input element corresponding to each attribute of an object represented by an expression.
Example:
A. @ HTML. editor ("name") output; <input class = "text-box single-line" id = "name" name = "name" type = "text" value = ""/>
B. It is the input initialization value during loading. Here the viewbag attribute added by Asp.net MVC is used;
@ {Viewbag. namevalue = "zhangsan"; // namevalue is a dynamic type or viewdata ["namevalue"] = "zhangsan";} @ HTML. editor ("namevalue ") output <input class = "text-box single-line" id = "namevalue" name = "namevalue" type = "text" value = "James"/>
C. @ html. Editor ("name", model. Name)
The second parameter is the object additionalviewdata parameter, which mainly refers to the data of the view model (the model is a system. Web. MVC. model object, and the @ model student object is referenced on the loading page ),
However, I don't know why the default value is not displayed for input. I do not know if it is not supported in Asp.net mvc3. If you want to know it, let us explain it.
2. @ html. editorfor ()
Returns the input element corresponding to each attribute of an object represented by an expression, mainly for the strong type.
A, @ html. editorfor (mode => mode. Name)
If the returned view is assigned a value to the student object, <input class = "text-box single-line" id = "name" name = "name" type = "text" value = "default"/> "";
B. @ html. editorfor (mode => mode. Name, "templatename ")
The second parameter is the Template Name. The template definition:
First, create the folder editortemplates/templatename. cshtml in the directory view/shared/created: View/shared/editortemplates/templatename. cshtml
Note: editortemplates must be used as a folder.
Templatename. the cshtml code is: @ HTML. dropdownlist ("", new selectlist (new [] {"1", "2", "3"}) indicates a drop-down list with a value of 1, 2, 3.
In this case, you can call @ html. editorfor (mode => mode. Name, "templatename") to display it in a drop-down list. If a text box set in the template is displayed in a text box.
You can also add the [uihint ("templatename")] feature to the name attribute of the entity student. If you add this feature, you do not need to display the specified Template Name during the call.
Use @ html. editorfor (mode => mode. Name) to display the field in the drop-down list.
Equivalent to the input control in HTML
@ Html. editorfor (model => model. Age)
The page is displayed as follows: <input id = "Age" name = "Age" type = "text" value = ""/>
3. @ html. editorformodel ()
If the default value is used without any parameters, all information in the model is displayed cyclically, but must be placed in the loop.
For example, <input class = "text-box single-line" id = "name" name = "name" type = "text" value = ""/>
<Input class = "text-box single-line" id = "Age" name = "Age" type = "text" value = ""/>