2010-07-26 4 views
2

je l'itinéraire suivant:ASP.NET MVC2 et routage

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

Pourquoi ce code fonctionne:

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

Et cela ne:

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

Répondre

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

Vous devez le paramètre null

ActionLink ne marche pas avoir (LinkText, ActionName, contrôleur, Paramètres) mais n'a (LinkText, ActionName, contrôleur, Paramètres, htmlAttributes)

+0

Merci! J'ai raté le paramètre nul. –

1

Le premier est résolu à this overload

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

Il n'y a pas de surcharge de ActionLink qui prend trois chaînes et un objet. Le plus proche est this one qui prend deux chaînes et deux objets:

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

donc je m'y attendais pas à faire ce que vous voulez.