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. shp文件和地理数据库文件的区别

    存储文件结构不同.所能进行的计算也不同. https://blog.csdn.net/lucahan/article/details/51761610 对数据库操作更快更方便,如何证明?尤其是数据量比 ...

  2. 几种String对象方法的区别

    1.在String对象方法中,发现.slice()方法和.substring()方法的作用几乎相同,都是根据起始索引返回截取得到的字符串.经过查阅资料和实测得到区别: 正常情况下索引都为正值,返回值为 ...

  3. uniGUI日志的控制

    uniGUI日志的控制 (2015-10-12 08:30:29) 转载▼ 标签: unigui 分类: uniGUI uniGUI本身提供了日志功能,利用uniServerModule.Server ...

  4. common-io 文件监听例子

    package com.junge.spring.demo.commonio; import org.apache.commons.io.monitor.FileAlterationListenerA ...

  5. nginx 502 bad gateway 问题处理集锦

    一般看来, 这种情况可能是由于nginx默认的fastcgi进程响应的缓冲区太小造成的, 这将导致fastcgi进程被挂起, 如果你的fastcgi服务对这个挂起处理的不好, 那么最后就极有可能导致5 ...

  6. Android基础-系统架构分析,环境搭建,下载Android Studio,AndroidDevTools,Git使用教程,Github入门,界面设计介绍

    系统架构分析 Android体系结构 安卓结构有四大层,五个部分,Android分四层为: 应用层(Applications),应用框架层(Application Framework),系统运行层(L ...

  7. jQuery应用实例2:表格隔行换色

    这里是用JS实现的:http://www.cnblogs.com/xuyiqing/p/8376312.html 接下来利用上一篇提到的选择器利用jQuery实现: 发现原来多行代码这里只需要两行: ...

  8. Eclipse中java内存溢出

    1.点击Window --->Preferences,如下图  

  9. 干货:教你如何监控 Java 线程池运行状态

    之前写过一篇 Java 线程池的使用介绍文章<线程池全面解析>,全面介绍了什么是线程池.线程池核心类.线程池工作流程.线程池分类.拒绝策略.及如何提交与关闭线程池等. 但在实际开发过程中, ...

  10. HoloLens开发手记-硬件细节 Hardware Detail

    微软HoloLens是世界第一款完全无线缆的全息计算机.通过在新方式上赋予用户的全息体验,HoloLens重新定义了个人计算(Personal Computing).为了将3D全息图形固定到你周围的真 ...