Html.ActionLink 方法用于指向Controller的Action
ActionLink方法定义的代码
//页面显示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()); }
//页面显示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)); }
//页面显示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)); }
//页面显示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()); }
// 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)); }
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)); }
使用实例代码
<li> <%= Html.ActionLink("Home","Index")%> </li> <li> <%= Html.ActionLink("About","About")%> </li> <li> <%=Html.ActionLink("Products","Detail","Products" )%> </li> <li> <%=Html.ActionLink("Products","Detail","Products" ,2)%> </li>