MVC中的Html.ActionLink
2015-09-06 11:42
260 查看
以下使用参数文字说明:
linkText:生成的链接所显示的文字 类型:string
actionName:对应控制器的方法 类型:string
routeValues:向对应的action传递的参数 类型:object 或 RouteValueDictionary
controlName:指定控制器的名称 类型:string
htmlAttributes:设置<a>标签的属性 类型:object 或 IDictionary
protocol:指定访问协议如:http等 类型:string
hostName:指定访问域名 类型:string
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>
linkText:生成的链接所显示的文字 类型:string
actionName:对应控制器的方法 类型:string
routeValues:向对应的action传递的参数 类型:object 或 RouteValueDictionary
controlName:指定控制器的名称 类型:string
htmlAttributes:设置<a>标签的属性 类型:object 或 IDictionary
protocol:指定访问协议如:http等 类型:string
hostName:指定访问域名 类型:string
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>
相关文章推荐
- 111.html测试测量角度 自己看别人看了没用
- 在html静态页面按钮链接,给button加上提交的链接等方法
- 写个html下载swf
- HTML与XML的优缺点
- 从图片中提取html格式的布局
- html的块级元素和内联元素
- 【HTML】html 小技巧
- 1.html的基本概念的学习
- Web设计——初识HTML
- html.day02
- html.day01
- html cookie
- html基本构成元素
- innerHTML、innerText和outerHTML、outerText的区别
- Html入门学习总结
- html的table中不换行显示的效果
- html中的转义字符
- VS之mht文件显示
- 关于firefox的高度 html,body{ height:100%;}
- Html页中使用OCX控件