您的位置:首页 > Web前端 > HTML

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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: