MVC进阶学习--HtmlHelper控件解析(三)
2009-10-10 16:06
316 查看
1.LinkExtensions类
该类主要用于生成相关链接,主要扩展了ActionLink和RouteLink方法
2.ActionLink
ActionLink扩展方法主要实现一个连接,共有十个重载方法
ActionLink(string linkText,string actionName);
ActionLink(string linkText,string actionName,object routeValues);
ActionLink(string linkText,string actionName,object routeValues,object htmlAttributes);
ActionLink(string linkText,string actionName,RouteDictionary routeValues);
ActionLink(string linkText,string actionName,RouteDictionary routeValues,
IDictionary<string,object> htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName);
ActionLink(string linkText,string actionName,string controllerName,object routeValues,
object htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName,RouteDictionary routeValues,
IDictionary<string,object> htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName,string protocol,string hostName,
string fragment,object routeValues,object htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName,string protocol,string hostName,
string fragment,RouteValueDictionary routeValues,IDictionary<string,object> htmlAttributes);
2.RouteLink
RouteLink(string linkText,string routeName,object routeValues);
RouteLink(string linkText,string routeName,RouteValueDictionary routeValues);
RouteLink(string linkText,string routeName,object htmlAttributes);
RouteLink(string linkText,RouteValueDictionary routeValues,IDictionary<string,object> htmlAttributes);
RouteLink(string linkText,string routeName,object routeValues,object htmlAttributes);
RouteLink(string linkText,string routeName,
RouteValueDictionary routeValues, IDictionary<string,object> htmlAttributes);
RouteLink(string linkText,string routeName,string protocol,string hostName,
string fragment,object routeValues,object htmlAttributes);
RouteLink(string linkText,string routeName,string protocol,string hostName,
string fragment,RouteValueDictionary routeValues,IDictionary<string,object> htmlAttributes);
部分例子:
Code
<%=Html.ActionLink("链接1", "List")%>
在当前控制器内指向另外一个action
<br />
<%=Html.ActionLink("链接2", "List", new { controller="Home"})%>
使用url路由指定controller 的值
<br />
<%=Html.ActionLink("链接2", "List", new { controller="Home",page=1})%>
使用url路由指定controller 的值,并且传递一个参数
<br />
<%=Html.ActionLink("链接3", "List", new { controller = "Home" }, new { id="linktext"})%>
使用url路由指定controller 的值,并且指定其他的属性值
<br />
<%=Html.ActionLink("链接4", "List","Home")%>
使用参数设置controller 和 action
<br />
<%=Html.RouteLink("Start", new { controller = "Home", action = "List" })%>
<%=Html.RouteLink("Start", new { controller = "Home", action = "List" }, new { id="link1",@class="link_hover"})%>
-----注册url路由
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Start",
"{controller}/{action}",
new { controller="Home",action="Index"}
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
该类主要用于生成相关链接,主要扩展了ActionLink和RouteLink方法
2.ActionLink
ActionLink扩展方法主要实现一个连接,共有十个重载方法
ActionLink(string linkText,string actionName);
ActionLink(string linkText,string actionName,object routeValues);
ActionLink(string linkText,string actionName,object routeValues,object htmlAttributes);
ActionLink(string linkText,string actionName,RouteDictionary routeValues);
ActionLink(string linkText,string actionName,RouteDictionary routeValues,
IDictionary<string,object> htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName);
ActionLink(string linkText,string actionName,string controllerName,object routeValues,
object htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName,RouteDictionary routeValues,
IDictionary<string,object> htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName,string protocol,string hostName,
string fragment,object routeValues,object htmlAttributes);
ActionLink(string linkText,string actionName,string controllerName,string protocol,string hostName,
string fragment,RouteValueDictionary routeValues,IDictionary<string,object> htmlAttributes);
2.RouteLink
RouteLink(string linkText,string routeName,object routeValues);
RouteLink(string linkText,string routeName,RouteValueDictionary routeValues);
RouteLink(string linkText,string routeName,object htmlAttributes);
RouteLink(string linkText,RouteValueDictionary routeValues,IDictionary<string,object> htmlAttributes);
RouteLink(string linkText,string routeName,object routeValues,object htmlAttributes);
RouteLink(string linkText,string routeName,
RouteValueDictionary routeValues, IDictionary<string,object> htmlAttributes);
RouteLink(string linkText,string routeName,string protocol,string hostName,
string fragment,object routeValues,object htmlAttributes);
RouteLink(string linkText,string routeName,string protocol,string hostName,
string fragment,RouteValueDictionary routeValues,IDictionary<string,object> htmlAttributes);
部分例子:
Code
<%=Html.ActionLink("链接1", "List")%>
在当前控制器内指向另外一个action
<br />
<%=Html.ActionLink("链接2", "List", new { controller="Home"})%>
使用url路由指定controller 的值
<br />
<%=Html.ActionLink("链接2", "List", new { controller="Home",page=1})%>
使用url路由指定controller 的值,并且传递一个参数
<br />
<%=Html.ActionLink("链接3", "List", new { controller = "Home" }, new { id="linktext"})%>
使用url路由指定controller 的值,并且指定其他的属性值
<br />
<%=Html.ActionLink("链接4", "List","Home")%>
使用参数设置controller 和 action
<br />
<%=Html.RouteLink("Start", new { controller = "Home", action = "List" })%>
<%=Html.RouteLink("Start", new { controller = "Home", action = "List" }, new { id="link1",@class="link_hover"})%>
-----注册url路由
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Start",
"{controller}/{action}",
new { controller="Home",action="Index"}
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
相关文章推荐
- MVC进阶学习--HtmlHelper控件解析(一)
- MVC进阶学习--HtmlHelper控件解析(二)
- MVC进阶学习--HtmlHelper控件解析(四)
- MVC进阶学习--HtmlHelper控件解析(五)
- MVC进阶学习--HtmlHelper控件解析(一)
- MVC进阶学习--HtmlHelper之GridView控件拓展(三)
- MVC进阶学习--HtmlHelper之GridView控件拓展(一)
- MVC进阶学习--HtmlHelper之GridView控件拓展(四)
- MVC进阶学习--HtmlHelper之GridView控件拓展(五)
- MVC进阶学习--HtmlHelper之GridView控件拓展(二)
- ASP.NET 3.5 MVC 架构与实战笔记6 HtmlHelper控件解析
- ASP.NET 3.5 MVC 架构与实战笔记6 HtmlHelper控件解析
- asp.net mvc 中 htmlhelper 中各生成 html 控件函数的实现(表达式解析)
- (asp.net MVC学习)System.Web.Mvc.HtmlHelper学习及使用
- ASP.Net MVC开发基础学习笔记:二、HtmlHelper与扩展方法
- ASP.Net MVC开发基础学习笔记(2):HtmlHelper与扩展方法
- (asp.net MVC学习)System.Web.Mvc.HtmlHelper学习及使用
- Asp.Net MVC 学习心得 之 Html Helper
- ASP.Net MVC开发基础学习笔记(2):HtmlHelper与扩展方法
- (asp.net MVC学习)System.Web.Mvc.HtmlHelper学习及使用