Asp.net mvc 2 ASP.NET MVC2与路由
我有以下路线:Asp.net mvc 2 ASP.NET MVC2与路由,asp.net-mvc-2,routing,Asp.net Mvc 2,Routing,我有以下路线: routes.MapRoute( "edit_product", // Route name "Product/Edit/{productId}", // URL with parameters new { controller = "Product", action = "Edit", productId = UrlParameter
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 }) %>
首先是决心 没有需要三个字符串和一个对象的重载。最接近的是,它接受两个字符串和两个对象:
public static MvcHtmlString ActionLink(
this HtmlHelper htmlHelper,
string linkText,
string actionName,
Object routeValues,
Object htmlAttributes
)
所以我不希望它做你想做的事
<%: Html.ActionLink("Edit", "Edit", "Product",
new { productId = product.ProductId } , null) %>
您需要null参数
Actionlink没有LinkText、Actionname、Controller和参数,但有
LinkText、Actionname、Controller、Parameters、htmlAttributes谢谢!我错过了空参数。
<%: Html.ActionLink("Edit", "Edit", "Product",
new { productId = product.ProductId } , null) %>