HtmlHelper
FormExtensions静态类
BeginFormBeginRouteFormEndForm 三种类型
FormMethodPost优先级最高
可以在多个地方设置action参数htmlAttributes优先级别最高
BeginRouteForm扩展方法提供开发者使用
;
设置路由值字典类型的id值和class值
EndForm
<%HtmlEndForm() %>
代码
<%using (HtmlBeginForm(index home FormMethodPost new { action = /Controller/actionName }))
{%>
表单内容
<%}
%>
<%using (HtmlBeginForm(index AfIndex
new RouteValueDictionary { { id } }
FormMethodPost
new RouteValueDictionary { { class cssName } }
))
{%>
重载方法
<%}
%>
<%using (HtmlBeginRouteForm(new { action = action }))
{%>
BeginRouteForm扩展方法提供开发者使用
<%}
%>
<%HtmlEndForm() %>
InputExtensions类
CheckBoxHiddenPasswordRadioButtonTextBox五种类型
CheckBox
代码
<%=HtmlBeginForm(CheckBoxHome) %>
<fieldset>
<legend>设置字体</legend>
<%=HtmlCheckBox(MyCheckBoxtruenew{id=checkBox}) %>
<label for=checkBox>黑体</label>
<%=HtmlCheckBox(MyCheckBoxfalsenew{id=checkBox}) %>
<label for=checkBox>斜体</label>
<br/>
<input type=submit value=Submit />
</fieldset>
<%HtmlEndForm() %>
<asp:Content ID=Content ContentPlaceHolderID=MainContent runat=server>
<h>CheckBox</h>
<%=HtmlTextBox(t ViewData[t])%>
<%=HtmlTextBox(t ViewData[t])%>
</asp:Content>
public ActionResult CheckBox(FormCollection formcollection)
{
//通过索引获得复选框控件状态值字符串
bool myCheckBox = formcollection[]Contains(true)
//通过键值获得复选框控件状态值字符串
bool myCheckBox = formcollection[MyCheckBox]Contains(true)
if (myCheckBox)
ViewData[t] = 选中;
else
ViewData[t] = 未选中;
if (myCheckBox)
ViewData[t] = 选中;
else
ViewData[t] = 未选中;
return View()
}
Hidden
<%=HtmlHidden(name) %>
Password
<%=HtmlPassword(password) %>
RadioButton
<% using (HtmlBeginForm(RadioButton Home))
{%>
<fieldset>
<legend>设置字号</legend>
<%=HtmlRadioButton(MyRadioButtonMyValuetruenew{id=MyRadioButton})%>
<label for=MyRadioButton>
#</label>
<%=HtmlRadioButton(MyRadioButtonMyValuetruenew{id=MyRadioButton})%>
<label for=MyRadioButton>
#</label>
<input class=button type=submit value=提 交 />
</fieldset>
<%} %>
<h>RadioButton</h>
<%=HtmlTextBox(t ViewData[MyRadioButton])%>
public ActionResult RadioButton(FormCollection formcollection)
{
string radioButtion=formcollection[];
string radioButtion = formcollection[MyRadioButton];
ViewData[MyRadioButton] = radioButtion;
return View()
}
TextBox
<%=HtmlTextBox(Message) %>
<%=HtmlTextBox(myTextBox null new { size=})%>
LinkExtensions类
ActionLinkRouteLink两种类型
ActionLink
ActionLink扩展方法主要实现一个连接
<%=HtmlActionLink(actionlink About)%>
<%=HtmlActionLink(actionlink AboutHome)%>
RouteLink
<%=HtmlRouteLink(routLink default new { id = })%>
RenderPartialExtensions类
RenderPartial该用户控件主要用来显示数据表Categories
在ASPNET MVC中使用RenderPartial方法时的一些性能问题记住两点一是在ASPNET MVC应用程序发布到生产服务器时别忘了关闭Debug模式(对于ASPNET WebForm应用程序也是一样)二时尽可能的减少调用RenderPartial方法的次数如通过在UserControl中进行遍历等方法