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

你可能感兴趣的文章
apache 的 mod status 模块可能会泄漏服务器信息
查看>>
SpringBoot学习 (二) Spring Boot Security
查看>>
Nginx 的开发公司C 轮融资4300 万美元
查看>>
JVM:查看java内存情况命令
查看>>
-[TTRequestLoader connection:didReceiveResponse...
查看>>
程序Debug运行的时候,老是显示“0x755c9617 处最可能的异常: 0x000006B...
查看>>
apkplug主题切换功能之主题包打包编译-07
查看>>
手把手让你实现开源企业级web高并发解决方案
查看>>
circular buffer in Linux kernel
查看>>
Bug描述
查看>>
mac下的项目管理软件OmniPlan的使用
查看>>
iOS为网站添加图标到主屏幕以及增加启动画面
查看>>
matlab的一些用发plot颜色
查看>>
生存的现状及环境
查看>>
线程入门-使用Execcutor
查看>>
setNeedsLayout 与 setNeedsDisplay
查看>>
康托展开与逆康托展开
查看>>
hadoop 2.7.2 安装
查看>>
JAVA泛型详解——转
查看>>
#ifdef __cplusplus extern "C" { #endif 的解释<转>
查看>>