@ Html. EditorFor () Usage

Source: Internet
Author: User

@ 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 = ""/>

 

Actually, I found that @ Html. EditorFor (mode => mode. Name, "templateName") is written

@ Html. editorFor (mode => mode. name, @ Html. dropDownList ("", new SelectList (new [] {"1", "2", "3"}) can also be used. However, after Html is generated, the Input is still not clear.

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.