1 common
HtmlLabel 1.1 label
Html syntax : <label for= "UserName" > User name </label>
Razor Syntax :@Html. Labelfor(m = m.username)
1.2 <input type= "text"/>
Html Syntax :
<input id= "UserName" name= "UserName" type= "text" value= ""/>
@Html. textboxfor(m = m.username)
1.3 <input type= "hidden"/>
Html Syntax :
<input id= "UserName" name= "UserName" type= "hidden" value= ""/>
@Html. textboxfor(m = m.username)
1.4 <input type= "password"/> Label
Html Syntax :
<input id= "Userpass" name= "Userpass" type= "passwordfor" value= ""/>
@Html. passwordfor(m = m.userpass)
1.5 <input type= "Radio"/> Label
Html Syntax :
<Inputid= "Sex0" name= "Sex" span class= "attribute" >type= "Radio" value= "0"/ > Male <input id= "Sex1" name= "Sex" type= "Radio" value= "1"/> female <input id= "Sex2" name= "Sex" type=" Radio "value=" 2 "/> Confidential
@ Html . Radiobuttonfor (m=> m.sex, 0, new {@id = "Sex0"}) male
@ Html . Radiobuttonfor (m=> m.sex, 1, new {@id = "Sex1"}) Female
@ Html . Radiobuttonfor (m=> m.sex, 2, new {@id = "Sex2"}) Confidential
1.6 <input type= "checkbox"/> Label
Html Syntax :
<id=name=type=value="true"/>
@Html. passwordfor(m = m.userpass)
2 Link Address
@Url. Content ()
@Url. Action
2.1 Referencing CSS style files
Html Syntax :
<href="/content/style.css"/>
<href="@Url. Content ("~/content/style.css") "/>
2.2 Referencing JavaScript files
Html Syntax :
<src="/content/jquery.js" ></script>
<src="@Url. Content ("~/content/jquery.js") "></script>
2.3 Image Reference picture file
Html Syntax :
<src="/content/images/1.jpg"/>
<src="@Url. Content ("~/content/images/1.jpg") "></script>
2.4 Hyperlinks
Html Syntax :
<href="/register" > Register </a>
@Html. ActionLink ("Register")
Note:@Html. ActionLink has multiple overloads, specifically referencing the API documentation
3 Form 3.1 Normal submission Form
@using ( Html . BeginForm ()) {
Submit to this page by default
<input type= "Submit" value= "button"/>
}
3.2 Ajax Submission Form
@using (Ajax.beginform (new Ajaxoptions {updatetargetid= "Txtresult"}))
{
<input type= "Submit" value= "button"/>
<span id= "Txtresult"/>
}
ASP. MVC4 View layer _razor manipulating HTML elements