首页 技术 正文
技术 2022年11月19日
0 收藏 766 点赞 2,943 浏览 3151 个字

前言

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

重载格式

重载方法一:  ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName); 【默认在当前页面的控制器】

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

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

重载方法二:  ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues); 【默认在当前页面的控制器】

 调用方式:     @Html.ActionLink(“我是一个超链接”, “About”, new { ID = 1 })

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

重载方法三:  ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, RouteValueDictionary routeValues);【默认在当前页面的控制器】

 调用方式:    @ {

          RouteValueDictionary routevalue = new RouteValueDictionary();

          routevalue[“ID”] = 1;
          routevalue[“Type”] = “list”;

        }

         @Html.ActionLink(“我是一个超链接”, “About”, routevalue)

生成效果:   <a href=”/Home/About/1?Type=list”>我是一个超链接</a>

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

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

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

重载方法五:  ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, object routeValues, object htmlAttributes); 【默认在当前页面的控制器】

 调用方式:    @Html.ActionLink(“我是一个超链接”, “About”, new { ID = 1 },new { @class = “activelink”, target = “_blank” })

生成效果:    <a class=”activelink” href=”/Home/About/1″ target=”_blank”>我是一个超链接</a>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896