Original link: http://blog.csdn.net/pasic/article/details/7093802
Just because the original author said something, there are a lot of things as the basic knowledge, I have not mastered, so summed up here, the blue word I added.
@Html Helper is a simple description of the basic HTML with the corresponding @html helper, @Html basically contains the HTML of the form control and common HTML
In @html, the with for is primarily for strongly typed HTML types.
Used to describe tags in @html, define student objects for auxiliary instructions,
Public classstudent{/// <summary> ///name/// </summary> ///[DisplayName ("name")] Public stringName {Get; Set; } /// <summary> ///Age/// </summary> Public intAge {Get; Set; }}
Define @model Student on the cshtml page
Label label, implemented in the Labelextensions class
1, @Html. Label ()
Returns an HTML label element and the property name of the property represented by the specified expression.
Parameter: string expression,string labelText
Expressions: An expression that represents the property to display
LabelText: Display text
Cases:
@Html. Label ("weight") output:<for= "weight">weight</ label>@Html. Label ("name", "name") output:<for = "name"> name </label>
What is the lable for tag???
Definition and Usage
The For property specifies which form element the label binds to.
implicit and explicit contact
tags are typically associated with form controls in one of the following two ways: the form control as the content of the tag label, either implicitly, or by naming a target form ID for the for property under the <label> tag, which is an explicit form.
The above is the interpretation of the world, then the display is the ID, the implicit is the attribute for, use these two ways to map the form into form, do not know right.
2, @Html. Labelfor ()
Similar to @html.label (), but mainly for strongly typed
Cases:
@Html. Labelfor (Model=>mode. Name) Output:<label for= "Name">Name</label>@Html. Labelfor (Model=>mode. Name, "name") Output:<label for= "Name">Name</label>if the [DisplayName ("name")] attribute (reference System.ComponentModel;) is added to the entity above, it will be displayed:<label for= "Name">Name</label>It is convenient to display Chinese characters
Well, what's the strong type.
Strongly typed: Specifying the data type for all variables is called strongly typed.
A strong/weak type refers to the severity of a type check. Language has no type, weak type and strong type three kinds. There is no type of check, not even a distinction between instructions and data. Weak-type checks are weak and only strictly differentiate between instructions and data. Strong types are strictly checked at compile time.
Strongly typed languages do not allow two different types of variables to interoperate with each other before forcing a type conversion. Java, C #, Apex, and Python are all strongly typed languages.
3, @Html. Labelformodel ()
Example: @Html. Labelformodel ("name") Output: <label for= "" >name</label>
The editor tag, which represents the input form control in the application, is implemented in the Editorextensions
1, @Html. Editor ()
Returns an INPUT element that corresponds to each property in an object represented by an expression
Cases:
A, @Html. Editor ("name") output;<class= "Text-box single-line" ID= " Name " name=" name " type=" text " value=" "/>
Initializes the value for input at load time, where the ViewBag attribute is added with ASP.
@{ viewbag.namevalue= "Zhang San";//Namevalue for dynamic type or viewdata["Namevalue"]= "Zhang San"; } @Html. Editor ("Namevalue") output <class= "Text-box single-line" ID = "Namevalue" name= "Namevalue" type= "text" value = "Zhang San"/>
C, @Html. Editor ("name", Model.name)
The second parameter is the object Additionalviewdata parameter primarily for the view model of the data (model for the System.Web.Mvc.Model object, on the load page referencing the @model Student object),
But I do not know why input does not show the default value. Do not know is not not in ASP. NET MVC3 is not supported, want to know to give instructions under.
2, @Html. Editorfor ()
Returns an INPUT element that corresponds to each property in an object represented by an expression, mainly for strongly typed, which is generally used more often
A, @Html. Editorfor (Mode=>mode. Name)
If the returned view assigns a value to the student entity, the output output <input class= "Text-box single-line" id= "name" name= "name" type= "text" value= "Default value"/ > Otherwise value is "";
B, @Html. Editorfor (Mode=>mode. Name, "templatename")
The second parameter is the template name, which defines the template:
First create a folder in directory view/shared/editortemplates/templatename.cshtml that is: view/shared/editortemplates/templatename.cshtml
Note: It is important to use EditorTemplates as a folder
The templatename.cshtml code is: @Html. DropDownList ("", New SelectList (New []{"1", "2", "3"}) represents a drop-down list with a value of
You can then call @html.editorfor (Mode=>mode. Name, "templatename"), is displayed as a drop-down list, which appears as a text box if a text box is set in the template.
Also, the name attribute in the entity student can be added with the [UIHint ("templatename")] attribute if you add this, you can not display the specified template name at the time of the call
With @html.editorfor (Mode=>mode. Name) can be displayed as a drop-down box, and all of this field will become a drop-down list
Equivalent to the input control in HTML
@Html. Editorfor (Model=>model. Age)
The page is displayed as: <input id= "Age" name= "age" type= "text" value= ""/>
3, @Html. Editorformodel ()
If you use the default value without any parameters, the loop displays all the information in the model, but it needs to be placed in a loop
such as: <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= ""/>
Razor Study (ii) @Html label