標籤:style blog http io ar color os sp java
1 常用 Html 標籤1.1 Label
Html 文法 :<label for="UserName">使用者名稱</label>
Razor文法:@Html.LabelFor(m => m.UserName)
1.2 <input type="text" />
Html 文法 :
<input id=" UserName " name=" UserName " type=" text " value="" />
Razor文法:
@Html.TextBoxFor(m => m.UserName)
1.3 <input type="hidden" />
Html 文法 :
<input id=" UserName " name=" UserName " type="hidden" value="" />
Razor文法:
@Html.TextBoxFor(m => m.UserName)
1.4 <input type="password" />標籤
Html 文法 :
<input id="UserPass" name="UserPass" type="PasswordFor" value="" />
Razor文法:
@Html.PasswordFor(m => m.UserPass)
1.5 <input type="radio" />標籤
Html 文法 :
<input id="Sex0" name="Sex" type="radio" value="0" /> 男<input id="Sex1" name="Sex" type="radio" value="1" /> 女<input id="Sex2" name="Sex" type="radio" value="2" /> 保密
Razor文法:
@ Html .RadioButtonFor(m=> m.Sex, 0, new { @id = "Sex0"}) 男
@ Html .RadioButtonFor(m=> m.Sex, 1, new { @id = "Sex1"}) 女
@ Html .RadioButtonFor(m=> m.Sex, 2, new { @id = "Sex2"}) 保密
1.6 <input type="checkbox" />標籤
Html 文法 :
<input id="RememberMe" name="RememberMe" type="checkbox" value="true" />
Razor文法:
@Html.PasswordFor(m => m.UserPass)
2 連結地址
@Url.Content()
@Url.Action
2.1 引用CSS樣式檔案
Html 文法 :
<link href="/Content/style.css" />
Razor文法:
<link href="@Url.Content("~/Content/style.css")" />
2.2 引用Javascript檔案
Html 文法 :
<script src="/Content/jquery.js"></script>
Razor文法:
<script src="@Url.Content("~/Content/jquery.js")"></script>
2.3 Image引用圖片檔案
Html 文法 :
<img src="/Content/images/1.jpg" />
Razor文法:
<script src="@Url.Content("~/Content/images/1.jpg")"></script>
2.4 超連結
Html 文法 :
<a href="/Register">註冊</a>
Razor文法:
@Html.ActionLink("註冊", "Register")
註:@Html.ActionLink有多個重載,具體參照MSDN API文檔
3 表單3.1 正常提交表單
@using( Html .BeginForm()){
//預設提交到本頁面
<input type="submit" value="Button"/>
}
3.2 Ajax提交表單
@using (Ajax.BeginForm(new AjaxOptions { UpdateTargetId="txtResult" }))
{
<input type="submit" value="Button"/>
<span id="txtResult"/>
}
ASP.NET MVC4 View層_Razor操作Html元素