ASP.NET MVC2 and routing
I have the following route:
routes.MapRoute(
"edit_product", // Route name
"Product/Edit/{productId}", // URL with parameters
开发者_运维技巧new { controller = "Product", action = "Edit",
productId = UrlParameter.Optional } // Parameter defaults
);
Why does this code works:
<%: Html.ActionLink("Edit", "Edit",
new { controller = "Product", productId = product.ProductId }) %>
And this doesn't:
<%: Html.ActionLink("Edit", "Edit", "Product",
new { productId = product.ProductId }) %>
<%: Html.ActionLink("Edit", "Edit", "Product",
new { productId = product.ProductId } , null) %>
You need the null parameter
Actionlink doesnt have (LinkText, Actionname, Controller, Parameters) but does have (LinkText, Actionname, Controller, Parameters, htmlAttributes)
The first is resolving to this overload
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
Object routeValues
)
There is no overload of ActionLink
that takes three strings and an object. The nearest is this one that takes two strings and two objects:
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
Object routeValues,
Object htmlAttributes
)
so I wouldn't expect it to do what you want.
精彩评论