ASP.NET MVC4 View層_Razor操作Html元素

來源:互聯網
上載者:User

標籤: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元素

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.