我有兩條路線在我的應用程序設置:ASP.NET路由MVC4問題 - 無法生成URL路由
routeCollection.MapRoute("CustomerActivity",
"Customer/{id}",
new { controller = "CustomerActivity", action = "DisplayDetails" },
new { id = @"^\d$" });
routeCollection.MapRoute("CustomerSearch",
"Customer/{*pathInfo}",
new
{
controller = "CustomerSearch",
action = "DisplaySearch"
});
傳入URL是正確地路由到正確的控制器/動作的配對。然而,在視圖我需要生成一個錨從而以查看客戶的詳細信息:
@Html.ActionLink(Model.Name, "DisplayDetails", "CustomerActivity", new { id = Model.Id }, null)
的問題,這是它實際上並沒有挑選任何路由起來的;我相信這是因爲CustomerActivity路線的限制。
@Html.RouteLink(Model.Name, "CustomerActivity", new { id = Model.Id })
我不能拿出上CustomerActivity約束,因爲這是一切停止落入這條路線:
我也使用RouteLink
沒有多少運氣嘗試。
添加CustomerActivity的副本沒有約束到最後似乎來解決這個問題,但我不到深刻的印象:
routeCollection.MapRoute("CustomerActivity",
"Customer/{id}",
new { controller = "CustomerActivity", action = "DisplayDetails" },
new { id = @"^\d$" });
routeCollection.MapRoute("CustomerSearch",
"Customer/{*pathInfo}",
new
{
controller = "CustomerSearch",
action = "DisplaySearch"
});
routeCollection.MapRoute("CustomerActivityUrlCreation",
"Customer/{id}",
new { controller = "CustomerActivity", action = "DisplayDetails" });
我能想到這樣做的唯一的其他東西是從根本上區分Url和擺脫對CustomerActivity的約束,但我不想這樣做。有沒有人有任何其他建議如何解決這個問題?
現貨!爲此非常感謝! – Steve