我試圖去處理MVC路由系統,但它並不像我期望的那樣工作。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" }
);
您是否可以包含您已定義的其他路線及其順序?可能是鏈接正在基於另一個路由定義構建。 – McGarnagle
@FloatLeft,只要確保如果你有其他類似的路線首先有更多的限制性路線,那麼就有更通用的路線。 –
hi dbaseman。已將前面的路線添加到問題的末尾。然而,你說得對,'NewCertificates'路線最後被宣佈爲 – FloatLeft