国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET MVC中HtmlHelper控件7個大類中各個控件使用詳解

2024-07-10 12:47:30
字體:
來源:轉載
供稿:網友

HtmlHelper類在命令System.Web.Mvc.Html之中,主要由7個靜態類組成,它們分別是FormExtensions類,InputExtensions類,LinkExtensions類,SelectExtensions類,TextExtensions類,ValidationExtensions類,RenderPartialExtensions類。

為了方便開發者使用HtmlHelper控件,在視圖ViewPage類中設置了一個屬性Html它就是HtmlHelper類型。

一.FormExtensions類

定義了3中類型的擴展方法BeginForm,BeginRouteForm,EndForm。

(1) BeginForm (實現表單定義的開始部分)

重載方法有13個:

BeginForm();

BeginForm(Object routeValues);

BeginForm(RouteValueDictionary routeValues);

BeginForm(string actionName,string controllerName);

BeginForm(string actionName,string controllerName,object routeValues);

BeginForm(string actionName,string controllerName,RouteValueDictionary routeValues);

BeginForm(string actionName,string controllerName,FormMethod method);

BeginForm(string actionName,string controllerName,object routeValues,FormMethod method);

BeginForm(string actionName,string controllerName,RouteValueDictionary routeVaues,FormMethod method);

BeginForm(string actionName,string controllerName,FormMethod method,object htmlAttributes);

BeginForm(string actionName,string controllerName,FormMethod method,IDictionary<string,object> htmlAttributes);

BeginForm(string actionName,string controllerName,object routeValues,FormMethod method,object htmlAttributes);

BeginForm(string actionName,string controllerName,RouteValueDictionary routeValues,FormMethod method,IDictionary<string,object> htmlAttributes);

對于第二個重載方法可以設置如下:

代碼如下:
Html.BeginForm(new{action="action",controller="actroller",id="2"});

在上述代碼中,設置了路由值的一個實例化對象,輸出的HTML語句是:

代碼如下:
<form action="actroller/action/2" method="post"/>

對于最后一個第十三個方法的最后一個參數是實例化對象設置相關屬性的值例如class,width等。

(2)BeginRouteForm (主要實現表單定義的開始部分,以路由的方法設置action的值)

有12個重載方法:

BeginRouteForm(object routeValues);

BeginRouteForm(RouteValueDictionary routeValues);

BeginRouteForm(string routeName);

BeginRouteForm(string routeName,object routeValues);

BeginRouteForm(string routeName,RouteValueDictionary routeValues);

BeginRouteForm(string routeName,FormMethod method);

BeginRouteForm(string routeName,object routeValues,FormMethod method);

……

對于第一個重載方法:

代碼如下:
Html.BeginRouteForm(new {action="action"});

代碼如下:
<form action="Home/action" method="post"/>Home是頁面所在的目錄

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 来安县| 淮南市| 六安市| 独山县| 葫芦岛市| 荥阳市| 建宁县| 东平县| 祁连县| 张家界市| 金山区| 灵台县| 睢宁县| 汉川市| 昌黎县| 鸡西市| 临泉县| 阿合奇县| 太仓市| 手游| 罗江县| 富源县| 宁国市| 赤壁市| 星座| 河南省| 五河县| 宁海县| 金寨县| 芜湖县| 海原县| 博兴县| 绥阳县| 榆中县| 若羌县| 砀山县| 镇巴县| 鄂托克前旗| 阿勒泰市| 斗六市| 房产|