首页 技术 正文
技术 2022年11月12日
0 收藏 980 点赞 3,086 浏览 6617 个字

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" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >这是一个连接</a>
<a href="/?page=1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >这是一个连接</a>
有其它Html属性的写法
<a href="/?Length=4" rel="external nofollow" id="link1">这是一个连接</a>
<a href="/" rel="external nofollow" rel="external nofollow" id="link1">这是一个连接</a>
QueryString与Html属性同时存在
<a href="/?page=1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" id="link1">这是一个连接</a>
<a href="/?page=1" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" 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" rel="external nofollow" >关于</a>
<a href="/about?page=1" rel="external nofollow" rel="external nofollow" >关于</a>
<a href="/about?page=1" rel="external nofollow" rel="external nofollow" 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;” >
生成结果:

<select id=”lstBox1″ multiple=”multiple” name=”lstBox1″>

<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;” >
生成结果:

<select id=”ddl1″ name=”ddl1″>

<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")  
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,905
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727