教程集 www.jiaochengji.com
教程集 >  脚本编程  >  Asp.net  >  正文 asp.net MVC进阶学习---HtmlHelper控件解析(三)

asp.net MVC进阶学习---HtmlHelper控件解析(三)

发布时间:2015-10-10   编辑:jiaochengji.com
asp.net MVC进阶学习---HtmlHelper控件解析(三)

    在网上看到的一个不错的asp.net MVC学习系列,希望可以帮助那些正在研究MVC的朋友们。
    本部分内容:asp.net MVC进阶学习---HtmlHelper控件解析(三) 。

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);

3.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);

      部分例子:
 

复制代码 代码如下:

<%=Html.ActionLink("链接1", "List")%>
   &nbsp;在当前控制器内指向另外一个action
   <br />
  
   <%=Html.ActionLink("链接2", "List", new { controller="Home"})%>
   &nbsp;使用url路由指定controller 的值
   <br />
  
   <%=Html.ActionLink("链接2", "List", new { controller="Home",page=1})%>
   &nbsp;使用url路由指定controller 的值,并且传递一个参数
   <br />
  
   <%=Html.ActionLink("链接3", "List", new { controller = "Home" }, new { id="linktext"})%>
   &nbsp;使用url路由指定controller 的值,并且指定其他的属性值
   <br />
  
   <%=Html.ActionLink("链接4", "List","Home")%>
   &nbsp;使用参数设置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);
        }

 原文作者:情缘 http://www.cnblogs.com/qingyuan

您可能感兴趣的文章:
asp.net MVC进阶学习---HtmlHelper控件解析(四)
asp.net MVC进阶学习---HtmlHelper控件解析(五)
asp.net MVC进阶学习---HtmlHelper之GridView控件拓展(一)
asp.net MVC进阶学习---HtmlHelper控件解析(三)
asp.net MVC进阶学习---HtmlHelper控件解析(一)
asp.net MVC进阶学习---HtmlHelper控件解析(二)
asp.net MVC进阶学习---HtmlHelper之GridView控件拓展(三)
asp.net MVC进阶学习---个性化目录结构(一)
asp.net MVC进阶学习---个性化目录结构(二)
asp.net MVC进阶学习---HtmlHelper之GridView控件拓展(二)

[关闭]
~ ~