ASP.NET MVC HtmlHelper之Html.ActionLink
前言
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>
ASP.NET MVC HtmlHelper之Html.ActionLink的更多相关文章
- ASP.NET MVC HtmlHelper用法集锦
ASP.NET MVC HtmlHelper用法集锦 在写一个编辑数据的页面时,我们通常会写如下代码 1:<inputtype="text"value='<%=View ...
- 扩展ASP.NET MVC HtmlHelper类
在这篇帖子中我会使用一个示例演示扩展ASP.NET MVC HtmlHelper类,让它们可以在你的MVC视图中工作.这个示例中我会提供一个简单的方案生成Html表格. HtmlHelper类 Htm ...
- asp.net mvc htmlHelper
ASP.NET MVC 3.0 HTML辅助方法 HTML辅助方法(html helper)是用来帮助生成HTML的方法. 1.HTML辅助方法应用实例 ◊ 生成form元素 @using (Ht ...
- 【ASP.NET MVC 】让@Ajax.ActionLink获取的数据不进Cache
刚玩这个东西的时候,发现IE会进Cache,不管怎么删除,修改,后台删除了,前台还是一样,找了一下,HTML5只提供了 <meta http-equiv="pragma" c ...
- ASP .NET MVC HtmlHelper扩展——简化“列表控件”的绑定
在众多表单元素中,有一类<select>元素用于绑定一组预定义列表.传统的ASP.NET Web Form中,它对应着一组重要的控件类型,即ListControl,我们经常用到DropDo ...
- ASP.NET MVC HtmlHelper 类的扩展方法
再ASP.NET MVC编程中用到了R语法,在View页面编辑HTML标签的时候,ASP.NET MVC 为我们准备好了可以辅助我们写这些标签的办法,它们就是HtmlHelper.微软官方地址是:ht ...
- [转]ASP.NET MVC HtmlHelper扩展之Calendar日期时间选择
本文转自:http://blog.bossma.cn/asp_net_mvc/asp-net-mvc-htmlhelper-calendar-datetime-select/ 这里我们扩展HtmlHe ...
- C# ASP.NET MVC HtmlHelper用法大全
UrlHrlper 下面的两个地址一样的功能 下边这个防止路由规则改变 比如UserInfo/Index改为UserInfo-Index,使用下面的不受影响 另一种形式的超链接: <%: Htm ...
- ASP.NET MVC HtmlHelper用法大全
HTML扩展类的所有方法都有2个参数: 以textbox为例子public static string TextBox( this HtmlHelper htmlHelper, string name ...
随机推荐
- Concurrency并发性
今天看了有关性能的文章,性能也是客户所看重的. 文章推荐看了软件编程并发性. 就按书上敲了网址看:http://www.gotw.ca/publications/concurrency-ddj.htm ...
- ASP.NET MVC 和 Ruby 相结合的Web框架Oak
在http://www.asp.net/mvc/open-source 上有个项目Oak: Frictionless development for ASP.NET MVC single page w ...
- EQueue - 一个纯C#写的分布式消息队列介绍2
一年前,当我第一次开发完EQueue后,写过一篇文章介绍了其整体架构,做这个框架的背景,以及架构中的所有基本概念.通过那篇文章,大家可以对EQueue有一个基本的了解.经过了1年多的完善,EQueue ...
- Angular遇上CoffeeScript - NgComponent封装
CoffeeScript是基于JavaScript的一门扩展小巧语言,它需要编译成JavaScript,然后再运行与浏览器或者Nodejs平台.JavaScript由于商业原因10天时间就匆忙诞生,所 ...
- 《HiWind企业快速开发框架实战》(0)目录及框架简介
<HiWind企业快速开发框架实战>(0)目录及框架简介 本系列主要介绍一款企业管理系统快速开发框架,该框架旨在快速完成企业管理系统,并实现易维护可移植的目标. 使用逐个系统模块进行编码的 ...
- MySQL 权限
create user创建用户 CREATE USER li@localhost IDENTIFIED BY 'li'; 授予用户li数据库person的所有权限,并允许用户li将数据库person的 ...
- Java动态编译
程序产生过程 下图展示了从源代码到可运行程序的过程,正常情况下先编译(明文源码到字节码),后执行(JVM加载字节码,获得类模板,实例化,方法使用).本文来探索下当程序已经开始执行,但在.class甚至 ...
- Nginx服务器之基础学习
一.Nginx介绍 nginx:Nginx是一种软件服务器(轻量级),故它最主要的功能就是可以与服务器硬件结合,我们的应用程序可以放在nginx服务器上进行发布,已达到让网民浏览的效果.除此自外,Ng ...
- Android笔记——判断程序是否第一次启动
public class Welcome extends Activity { private final long SPLASH_LENGTH = 2000; Handler handler = n ...
- python基础篇----字符串unicode
python中处理中文常要用到unicode,因为较容易遇到字符串编码的问题,我一般都是将字符串统一转成unicode去处理 python中定义一个unicode字符串,可以在字符串前面加u: str ...