2010-07-26 88 views
2

我有以下途徑:ASP.NET MVC2和路由

routes.MapRoute(
    "edit_product",        // Route name 
    "Product/Edit/{productId}",     // URL with parameters 
    new { controller = "Product", action = "Edit", 
      productId = UrlParameter.Optional }  // Parameter defaults 
); 

爲什麼這個代碼的工作:

<%: Html.ActionLink("Edit", "Edit", 
    new { controller = "Product", productId = product.ProductId }) %> 

這並不:

<%: Html.ActionLink("Edit", "Edit", "Product", 
    new { productId = product.ProductId }) %> 

回答

4
<%: Html.ActionLink("Edit", "Edit", "Product", 
    new { productId = product.ProductId } , null) %> 

您需要的空參數

ActionLink的可是沒有(連結文字,Actionname,控制器,參數),但確實有 (連結文字,Actionname,控制器,參數,htmlAttributes)

+0

謝謝!我錯過了null參數。 – 2010-07-26 15:34:24

1

第一正在解決到this overload

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper, 
    string linkText, 
    string actionName, 
    Object routeValues 
) 

ActionLink沒有超載需要三個字符串和一個對象。最近的是this one,它有兩個字符串和兩個對象:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper, 
    string linkText, 
    string actionName, 
    Object routeValues, 
    Object htmlAttributes 
) 

,所以我不希望它做你想要的。