博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET MVC5总结(一)@HTML和对应的HTML
阅读量:7100 次
发布时间:2019-06-28

本文共 3122 字,大约阅读时间需要 10 分钟。

HtmlHelper用来在视图中呈现 HTML 控件,主要分为以下几类:

1.ActionLink - 链接到操作方法

1 @Html.ActionLink("这是一个连接", "Index", "Home") 2 带有QueryString的写法 3 @Html.ActionLink("这是一个连接", "Index", "Home", new { page=1 },null) 4 @Html.ActionLink("这是一个连接", "Index", new { page=1 }) 5 有其它Html属性的写法 6 @Html.ActionLink("这是一个连接", "Index", "Home", new { id="link1" }) 7 @Html.ActionLink("这是一个连接", "Index",null, new { id="link1" }) 8 QueryString与Html属性同时存在 9 @Html.ActionLink("这是一个连接", "Index", "Home", new { page = 1 }, new { id = "link1" })10 @Html.ActionLink("这是一个连接", "Index" , new { page = 1 }, new { id = "link1" })

对应的HTML

1 这是一个连接 2 带有QueryString的写法 3 这是一个连接 4 这是一个连接 5 有其它Html属性的写法 6 这是一个连接 7 这是一个连接 8 QueryString与Html属性同时存在 9 这是一个连接10 这是一个连接
RoutLink @Html.RouteLink("关于", "about", new { })带QueryString@Html.RouteLink("关于", "about", new { page = 1 })@Html.RouteLink("关于", "about", new { page = 1 }, new { id = "link1" })

对应的HTML

2.BeginForm - 标记窗体的开头并链接到呈现该窗体的操作方法

1 @using(Html.BeginForm("index","home",FormMethod.Post)){2 3 }4 Or5 @Html.BeginForm("index", "home", FormMethod.Post)6 @Html.EndForm()

对应的HTML

3.CheckBox  - 呈现复选框

1 @Html.CheckBox("chk1",true) 2 @Html.CheckBox("chk1", new { @class="checkBox"}) 3 @Html.CheckBoxFor(a =>a.IsVaild, new { @class = "checkBox" })

对应的HTML

1 2 3 

4.DropDownList  - 呈现下拉列表

@Html.DropDownList("ddl1", (SelectList)ViewData["Categories"],  "--Select One--")@Html.DropDownListFor(a => a.CategoryName, (SelectList)ViewData["Categories"], "--Select One--", new { @class = "dropdownlist" })

对应的HTML

1 12 

5.ListBox - 呈现列表框

1 @Html.ListBox("lstBox1",(SelectList)ViewData["Categories"])2 @Html.ListBoxFor(a => a.CategoryName, (SelectList)ViewData["Categories"])

对应的HTML

1 11 

6.Password - 呈现用于输入密码的文本框

@Html.PasswordFor(m => m.Password, new { @class = "form-control input_width", @placeholder = "请输入密码" })

对应的HTML

7.RadioButton  - 呈现单选按钮

@Html.RadioButtonFor(m => m.Gender, "Male")@Html.RadioButtonFor(m => m.Gender, "Female")

对应的HTML

 Male Female

8.TextArea - 呈现文本区域(多行文本框)

@Html.TextArea("input5", Model.CategoryName, 3, 9,null)@Html.TextAreaFor(a => a.CategoryName, 3, 3, null)

对应的HTML

9.TextBox  - 呈现文本框

@Html.TextBox("input1") @Html.TextBox("input2",Model.CategoryName,new{ @style = "width:300px;" }) @Html.TextBox("input3", ViewData["Name"],new{ @style = "width:300px;" }) @Html.TextBoxFor(a => a.CategoryName, new { @style = "width:300px;" })

对应的HTML

10.Partial视图RenderPartial(直接将用户控件嵌到该界面)

@Html.RenderPartial("DinnerForm")
@{ Html.RenderPartial("~/Areas/Comm/Views/Shared/LogOnUserControl.ascx"); }

11.Label

@Html.Label("GenreId")

对应的HTML

12.Url.Content

转载于:https://www.cnblogs.com/bobo-show/p/5746389.html

你可能感兴趣的文章
hdu2222-Keywords Search 【AC自动机】
查看>>
Jsp使用HttpSessionBindingListener实现在线人数记录
查看>>
SQL中的等号、IN、LIKE三者的比较
查看>>
JSPatch 成长之路
查看>>
vuejs学习网站推荐
查看>>
如何在Fedora或CentOS上使用Samba共享
查看>>
乐视mysql面试题
查看>>
常用文件扩展名
查看>>
如何让Linux定时任务crond以秒为单位执行(如每隔3秒)
查看>>
二叉树的构造
查看>>
linux中线程池【转】
查看>>
php通过字符串生存hashCode
查看>>
SQL Server memory – Internals
查看>>
$.ajax和$.post的区别(前者根据key-value/后者根据形参)
查看>>
Node.js SDK与fabric链码交互开发
查看>>
vue - index.html
查看>>
神经网络优化(二) - 激活函数和损失函数
查看>>
传const引用代替传值
查看>>
android 传感器使用 Compass指南针的实现功能
查看>>
以不同用户身份运行程序
查看>>