HtmlHelper用来在视图中呈现 HTML 控件。

以下列表显示了当前可用的一些 HTML 帮助器。 本主题演示所列出的带有星号 (*) 的帮助器。

  • ActionLink — Links to an action method." style="margin: 0px; padding: 0px;" >ActionLink - 链接到操作方法。

  • BeginForm * — Marks the start of a form and links to the action method that renders the form." style="margin: 0px; padding: 0px;" >BeginForm * - 标记窗体的开头并链接到呈现该窗体的操作方法。

  • CheckBox * — Renders a check box." style="margin: 0px; padding: 0px;" >CheckBox * - 呈现复选框。

  • DropDownList * — Renders a drop-down list." style="margin: 0px; padding: 0px;" >DropDownList * - 呈现下拉列表。

  • Hidden — Embeds information in the form that is not rendered for the user to see." style="margin: 0px; padding: 0px;" >Hidden - 在窗体中嵌入未呈现的信息以供用户查看。

  • ListBox — Renders a list box." style="margin: 0px; padding: 0px;" >ListBox * - 呈现列表框。

  • Password — Renders a text box for entering a password." style="margin: 0px; padding: 0px;" >Password - 呈现用于输入密码的文本框。

  • RadioButton * — Renders a radio button." style="margin: 0px; padding: 0px;" >RadioButton * - 呈现单选按钮。

  • TextArea — Renders a text area (multi-line text box)." style="margin: 0px; padding: 0px;" >TextArea - 呈现文本区域(多行文本框)。

  • TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >TextBox * - 呈现文本框

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >1.ActionLink

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

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >生成结果为:

带有QueryString的写法
<a href="/?page=1">这是一个连接</a>
<a href="/?page=1">这是一个连接</a>
有其它Html属性的写法
<a href="/?Length=4" id="link1">这是一个连接</a>
<a href="/" id="link1">这是一个连接</a>
QueryString与Html属性同时存在
<a href="/?page=1" id="link1">这是一个连接</a>
<a href="/?page=1" id="link1">这是一个连接</a>

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >2.RouteLink
跟ActionLink在功能上一样。

@Html.RouteLink("关于", "about", new { })
带QueryString
@Html.RouteLink("关于", "about", new { page = 1 })
@Html.RouteLink("关于", "about", new { page = 1 }, new { id = "link1" })

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >生成结果:

<a href="/about">关于</a>
<a href="/about?page=1">关于</a>
<a href="/about?page=1" id="link1">关于</a>

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >3.Form   2种方法

@using(Html.BeginForm("index","home",FormMethod.Post)){

}
Or
TextBox * — Renders a text box." style="margin: 0px; padding: 0px; line-height: 1.5 !important; background-color: rgb(255, 255, 255);" >@Html.BeginForm("index", "home", FormMethod.Post)
@Html.EndForm()

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >生成结果:
<form action="/home/index" method="post"></form>

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >
4.TextBox , Hidden ,

@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;" })

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >生成结果:

<input id="input1" name="input1" type="text" value="" />
<input id="input2" name="input2" style="width:300px;" type="text" value="Beverages" />
<input id="input3" name="input3" style="width:300px;" type="text" value="" />
<input id="CategoryName" name="CategoryName" style="width:300px;" type="text" value="Beverages" />

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >5.TextArea

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

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >生成结果:

<textarea cols="9" id="input5" name="input5" rows="3">Beverages</textarea>
<textarea cols="3" id="CategoryName" name="CategoryName" rows="3">Beverages</textarea>

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >
6.CheckBox

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

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >生成结果:

<input checked="checked" id="chk1" name="chk1" type="checkbox" value="true" /><input name="chk1" type="hidden" value="false" />

<input class="checkBox" id="chk1" name="chk1" type="checkbox" value="true" /><input name="chk1" type="hidden" value="false" />

<input checked="checked" class="checkBox" id="IsVaild" name="IsVaild" type="checkbox" value="true" /><input name="IsVaild" type="hidden" value="false" />

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >7.ListBox

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

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >
生成结果:

<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option selected="selected" value="3">Confections</option>
<option value="4">Dairy Products</option>
<option value="5">Grains/Cereals</option>
<option value="6">Meat/Poultry</option>
<option value="7">Produce</option>
<option value="8">Seafood</option>
</select>
<select id="CategoryName" multiple="multiple" name="CategoryName">
<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option value="3">Confections</option>
<option value="4">Dairy Products</option>
<option value="5">Grains/Cereals</option>
<option value="6">Meat/Poultry</option>
<option value="7">Produce</option>
<option value="8">Seafood</option>
</select>

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >
8.DropDownList

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

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >
生成结果:

<option value="">--Select One--</option>
<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option selected="selected" value="3">Confections</option>
<option value="4">Dairy Products</option>
<option value="5">Grains/Cereals</option>
<option value="6">Meat/Poultry</option>
<option value="7">Produce</option>
<option value="8">Seafood</option>
</select>
<select class="dropdownlist" id="CategoryName" name="CategoryName">
<option value="">--Select One--</option>
<option value="1">Beverages</option>
<option value="2">Condiments</option>
<option value="3">Confections</option>
<option value="4">Dairy Products</option>
<option value="5">Grains/Cereals</option>
<option value="6">Meat/Poultry</option>
<option value="7">Produce</option>
<option value="8">Seafood</option>
</select>

TextBox * — Renders a text box." style="margin: 0px; padding: 0px;" >9.Partial 视图模板
类似于webform里的自定义控件。

@Html.RenderPartial("DinnerForm")  

MVC HtmlHelper用法的更多相关文章

  1. ASP.NET MVC HtmlHelper用法集锦

    ASP.NET MVC HtmlHelper用法集锦 在写一个编辑数据的页面时,我们通常会写如下代码 1:<inputtype="text"value='<%=View ...

  2. MVC HtmlHelper用法大全

    MVC HtmlHelper用法大全HtmlHelper用来在视图中呈现 HTML 控件.以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ·Actio ...

  3. C# ASP.NET MVC HtmlHelper用法大全

    UrlHrlper 下面的两个地址一样的功能 下边这个防止路由规则改变 比如UserInfo/Index改为UserInfo-Index,使用下面的不受影响 另一种形式的超链接: <%: Htm ...

  4. MVC HtmlHelper用法(一)@Html.BeginForm的使用总结

    1.@using(Html.BeginForm()){}                                                      //提交到当前页面 2.@using ...

  5. ASP.NET MVC HtmlHelper用法大全

    HTML扩展类的所有方法都有2个参数: 以textbox为例子public static string TextBox( this HtmlHelper htmlHelper, string name ...

  6. 【转】MVC HtmlHelper用法大全

    HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了当前可用的一些 HTML 帮助器. 本主题演示所列出的带有星号 (*) 的帮助器. ActionLink - 链接到操作方法. B ...

  7. [转]MVC HtmlHelper用法大全

    原文链接:http://www.cnblogs.com/jyan/archive/2012/07/23/2604474.html HtmlHelper用来在视图中呈现 HTML 控件. 以下列表显示了 ...

  8. 【MVC】ASP.NET MVC HtmlHelper用法大全

    1.ActionLink <%=Html.ActionLink("这是一个连接", "Index", "Home")%>   带 ...

  9. MVC中HtmlHelper用法大全参考

    MVC中HtmlHelper用法大全参考 解析MVC中HtmlHelper控件7个大类中各个控件的主要使用方法(1) 2012-02-27 16:25 HtmlHelper类在命令System.Web ...

随机推荐

  1. 339. Nested List Weight Sum

    https://leetcode.com/problems/nested-list-weight-sum/description/ Given a nested list of integers, r ...

  2. ABP框架系列之四十:(Notification-System-通知系统)

    Introduction Notifications are used to inform users on specific events in the system. ASP.NET Boiler ...

  3. 配置微信jssdk自定义分享

    前段时间做这个功能的时候遇到这个问题,之前的话是微信自动抓取界面第一张图,现在微信更新api,必须自行配置,接入jssdk,才能实现该功能. 详细可以查看微信的jssdk文档 微信官方开发者文档    ...

  4. Oracle存储过程,游标使用

    Oracle存储过程: 语法: CREATE [OR REPLACE] PROCEDURE procedure_name (arg1 [mode1] datatype1,arg2 [mode2] da ...

  5. PHP几种加密方式

    1.MD5() 2.Sha1() 3.urlencode()方法用于加密,urldecode()方法用于解密 4.base64_encode (  )  64位加密   base64_decode ( ...

  6. docker中gitlab-runner配置

    1.启动gitlab-runner docker run -d --name gitlab-runner --restart always \ -v /opt/data/gitlab-runner/c ...

  7. Android交流会-碎片Fragment,闲聊单位与尺寸

    女孩:又周末了哦~ 男孩:那么今日来开个交流会,我们也学一学人家高大尚的大会,自己开一个,广州站,Android开发攻城狮交流会~ 1.Fragment概要: Android从3.0开始引入了Frag ...

  8. MySQL slow_log日志表出现非法字段值

    背景 从mysql.slow_log 获取慢查询日志很慢,该表是csv表,没有索引. 想添加索引来加速访问,而csv引擎不能添加索引(csv引擎存储是以逗号分割的文本来存储的),只能改存储引擎来添加索 ...

  9. Vue2.0+组件库总结

    转自:https://blog.csdn.net/lishanleilixin/article/details/84025459 UI组件 element - 饿了么出品的Vue2的web UI工具套 ...

  10. 急速JavaScript全栈教程

    3 天前  ·  3k 次阅读 急速JavaScript全栈教程 javascript node.js  mongodb 140 自从一年前发布了Vuejs小书的电子书,也有些日子没有碰过它们了,现在 ...