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

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"/> 
} 

  

转载于:https://www.cnblogs.com/c-x-a/p/6872579.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值