[教程]ASP.Net MVC的Html.ActionLink解析
- 开发笔记
- 2008-05-13
- 55热度
- 0评论
Html.ActionLink 方法用于指向Controller的Action
ActionLink方法定义的代码
[code]
//页面显示linkText指向Global.asax.cs中默认的Controller对象的actionName方法
public string ActionLink(string linkText, string actionName) {
if (String.IsNullOrEmpty(linkText)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
if (String.IsNullOrEmpty(actionName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
return GenerateLink(linkText, null /* routeName */, actionName, null /* controllerName */, new RouteValueDictionary());
}
[/code]
[code]
//页面显示linkText指向默认Global.asax.cs中默认的Controller对象的actionName方法并且带的参数值values
public string ActionLink(string linkText, string actionName, object values) {
if (String.IsNullOrEmpty(linkText)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
if (String.IsNullOrEmpty(actionName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
return GenerateLink(linkText, null /* routeName */, actionName, null /* controllerName */, new RouteValueDictionary(values));
}
[/code]
[code]
//页面显示linkText指向定义的RouteValueDictionary中的Controller对象的actionName方法
public string ActionLink(string linkText, string actionName, RouteValueDictionary valuesDictionary) {
if (String.IsNullOrEmpty(linkText)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
if (String.IsNullOrEmpty(actionName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
if (valuesDictionary == null) {
throw new ArgumentNullException("valuesDictionary");
}
return GenerateLink(linkText, null /* routeName */, actionName, null /* controllerName */, new RouteValueDictionary(valuesDictionary));
}
[/code]
[code]
//页面显示linkText指向ControllerName对应的Controller的actionName方法
public string ActionLink(string linkText, string actionName, string controllerName) {
if (String.IsNullOrEmpty(linkText)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
if (String.IsNullOrEmpty(actionName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
if (String.IsNullOrEmpty(controllerName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "controllerName");
}
return GenerateLink(linkText, null /* routeName */, actionName, controllerName, new RouteValueDictionary());
}
[/code]
[code]
//
public string ActionLink(string linkText, string actionName, string controllerName, object values) {
if (String.IsNullOrEmpty(linkText)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
if (String.IsNullOrEmpty(actionName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
if (String.IsNullOrEmpty(controllerName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "controllerName");
}
return GenerateLink(linkText, null /* routeName */, actionName, controllerName, new RouteValueDictionary(values));
}
[/code]
[code]
public string ActionLink(string linkText, string actionName, string controllerName, RouteValueDictionary valuesDictionary) {
if (String.IsNullOrEmpty(linkText)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "linkText");
}
if (String.IsNullOrEmpty(actionName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
if (String.IsNullOrEmpty(controllerName)) {
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "controllerName");
}
if (valuesDictionary == null) {
throw new ArgumentNullException("valuesDictionary");
}
return GenerateLink(linkText, null /* routeName */, actionName, controllerName, new RouteValueDictionary(valuesDictionary));
}
[/code]
使用实例代码
[code]
[/code]