博客
关于我
强烈建议你试试无所不能的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

你可能感兴趣的文章
程序员的运动乐趣
查看>>
在阿里云上开放Redis默认的6379端口
查看>>
护照申办证明
查看>>
搜索引擎优化最为关键的七个地方
查看>>
sudo详解
查看>>
nginx启动 停止 重启等 管理脚本
查看>>
ubuntu12.04 安装BeautifulSoup遇到的问题
查看>>
Java删除文件夹和文件
查看>>
docker学习系列一:初识docker
查看>>
如何修改ssh的端口号?
查看>>
我的友情链接
查看>>
mysql binlog配置
查看>>
使用正则表达式匹配嵌套Html标签
查看>>
书摘---创业36条军规8:资本的五个问题
查看>>
arduino 配eclipse的博客,有空看下
查看>>
linux下用mail命令发送邮件
查看>>
MongoDB复制集部署和基本管理
查看>>
单链表面试题(二)从头到尾打印单链表
查看>>
strcmp()
查看>>
CET,UTC,GMT,CST几种常见时间概述
查看>>