zoukankan      html  css  js  c++  java
  • MVC中的Html.ActionLink

    以下使用参数文字说明:

    1. linkText:生成的链接所显示的文字         类型:string
    2. actionName:对应控制器的方法          类型:string
    3. routeValues:向对应的action传递的参数      类型:object 或 RouteValueDictionary
    4. controlName:指定控制器的名称           类型:string
    5. htmlAttributes:设置<a>标签的属性                   类型:object 或 IDictionary
    6. protocol:指定访问协议如:http等         类型:string
    7. hostName:指定访问域名             类型:string
    8. fragment:指定访问锚点              类型:string

    重载一:Html.ActionLink("linkText","actionName")【默认当前页面控制器】

    调用:@Html.ActionLink("默认当前页面控制器", "About")

    生成效果:<a href="/Home/About">默认当前页面控制器</a>

    重载二:Html.ActionLink("linkText","actionName",routeValues)

    调用:

      routeValues Is object:

      @Html.ActionLink("默认当前页面控制器", "About", new { id = 1, type = "Dic" })

      routeValues Is RouteValueDictionary:

      @RouteValueDictionary Dictionary = new RouteValueDictionary();
      @Dictionary["id"] = 1;
      @Dictionary["type"] = "Dic";
      

      @Html.ActionLink("默认当前页面控制器", "About", Dictionary)

    生成效果:<a href="/Home/About?classid=1">默认当前页面控制器</a>

    重载三:Html.ActionLink("linkText","actionName","controlName")

    调用:@Html.ActionLink("默认当前页面控制器", "About", "Home")

    生成效果:<a href="/Home/About">默认当前页面控制器</a>

    重载四:Html.ActionLink("linkText","actionName",routeValues,htmlAttributes)

    调用:

      htmlAttributes Is object:

      @Html.ActionLink("首页", "Index", "Home", null, new { @class = "active", target = "_blank" })%>【注:由于class是保留关键字,所以一定要写成@class】

      htmlAttributes Is IDictionary:

      @IDictionary<string, object> AttrDictionary = new Dictionary<string, object>();

      @AttrDictionary["class"] = "active";

      @AttrDictionary["target"] = "_blank";

    生成效果:<a class="active" href="/" target="_blank">首页</a>

    重载五:Html.ActionLink("linkText","actionName","controlName","protocol","hostName","fragment",routeValues,htmlAttributes)

    调用:@Html.ActionLink("关于我们", "About", "Home", "http", "localhost", "top", null, null)

    生成效果:<a href="http://localhost:12120/Home/About#top">关于我们</a>

  • 相关阅读:
    一些Vim使用的小技巧
    virtualbox centos安装增强工具和Centos与VirtualBox共享文件夹设置
    (转) centos7 RPM包之rpm命令
    (转)Navicat_12安装与破解,亲测可用!!!
    (转)2019年 React 新手学习指南 – 从 React 学习线路图说开去
    (转)react 项目构建
    (转)python3:类方法,静态方法和实例方法以及应用场景
    (转)SQLAlchemy入门和进阶
    (转)面向对象(深入)|python描述器详解
    (转)CentOS 7.6 上编译安装httpd 2.4.38
  • 原文地址:https://www.cnblogs.com/jack022/p/4785073.html
Copyright © 2011-2022 走看看