我正试图掌握MVC路由系统,但它没有像我期望的那样工作。
说我已经定义了这条路线:
context.MapRoute(
"NewCertificates",
"NewQuote/GetCertificate/{date}/{id}",
new { area = "NewQuote", controller = "Quote", action = "GetCertificate" },
new[] { "Acme.Areas.NewQuote.Controllers" }
);
我视图中的此动作链接:
@Html.ActionLink("Click Here", "GetCertificate", new { controller = "Quote", area = "NewQuote", date = "20121219", id = "acme" })
我希望生成的网址如下所示:
http://localhost:50582/NewQuote/GetCertificate/20121219/acme
但我得到了:
http://localhost:50582/NewQuote/GetCertificate/acme?date=20121219
谁能告诉我为什么会这样?
编辑以显示上述路线之前的路线:
context.MapRoute(
"NewQuoteValidation",
"NewQuote/Validation/{action}/{id}",
new { area = "NewQuote", controller = "Validation", action = "IsImeiAvailable", id = UrlParameter.Optional },
new[] { "Acme.Areas.NewQuote.Controllers" }
);
context.MapRoute(
"NewAjax",
"NewQuote/Ajax/{action}/{id}",
new { area = "NewQuote", controller = "Ajax", action = "Index", id = UrlParameter.Optional },
new[] { "Acme.Areas.NewQuote.Controllers" }
);
context.MapRoute(
"NewQuote",
"NewQuote/{action}/{id}",
new { area = "NewQuote", controller = "Quote", action = "Select", id = UrlParameter.Optional },
new[] { "Acme.Areas.NewQuote.Controllers" }
);
答案 0 :(得分:4)
另一个先前的路由定义可能声称拥有ActionLink
定义的所有权。您可能想尝试:
Html.RouteLink
@Html.RouteLink("Click Here",
// route name
"NewCertificates",
// route attributes
new { controller = "Quote", area = "NewQuote", date = "20121219", id = "acme" })
答案 1 :(得分:0)
尝试此操作来呼叫您的路线:
@ Html.RouteLink(“Click Here”,“NewCertificates”,new {controller =“Quote”,area =“NewQuote”,id =“acme”})