码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET MVC HtmlHelper之Html.ActionLink

时间:2016-04-03 01:47:44      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:

前言

   ActionLink用于生成超链接,方法用于指向Controller的Action。

扩展方法与参数说明

     ActionLink扩展方法如下:

    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName);

    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues);
       
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues);
       
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName);
       
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes);
       
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes);
       
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes);
        
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes);
       
    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, object routeValues, object htmlAttributes);

    public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, string protocol, string hostName, string fragment, RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes);

  参数类型说明如下:

参数名称 参数说明 参数类型
linkText 生成超链接所显示的文字 string
actionName 向对应Action中的方法 Object或RouteValueDictionary
controllerName 指定Conntroller的名称  string
 htmlAttributes 设置<a>标签的属性  Object或RouteValueDictionary
 routeValues 向对应的Action中传递的参数 Object或RouteValueDictionary
 protocol 指定访问协议如:http等 string
 fragment 指定访问锚点 string
 hostName: 指定访问域名 string

重载格式

 重载方法一:  MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName);

 调用方式:     @Html.ActionLink("我是一个超链接","About")

 生成效果:    <a href="/Home/About">我是一个超链接</a>

 

ASP.NET MVC HtmlHelper之Html.ActionLink

标签:

原文地址:http://www.cnblogs.com/liujie2272/p/5348741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!