我正在尝试掌握 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" })
我希望生成的 URL 看起来像:
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" }
);