Asp.net mvc MVC路由未按预期工作
我正在努力掌握MVC路由系统,但它并没有像我预期的那样工作 假设我已定义此路线:Asp.net mvc MVC路由未按预期工作,asp.net-mvc,Asp.net Mvc,我正在努力掌握MVC路由系统,但它并没有像我预期的那样工作 假设我已定义此路线: context.MapRoute( "NewCertificates", "NewQuote/GetCertificate/{date}/{id}", new { area = "NewQuote", controller = "Quote", action = "GetCertificate" }, new[] { "Acme.Areas.NewQu
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" }
);
另一个先前的路由定义很可能声称拥有
ActionLink
定义的所有权。您可能要尝试:
Html.RouteLink
另一个先前的路由定义很可能声称拥有
ActionLink
定义的所有权。您可能要尝试:
Html.RouteLink
请尝试拨打您的路线:
@RouteLink(“单击此处”、“新建证书”、新建{controller=“Quote”、area=“NewQuote”、id=“acme”})尝试以下方法调用您的路线:
@Html.RouteLink(“单击此处”、“新建证书”、“新建”{controller=“Quote”、area=“NewQuote”、id=“acme”})您可以包括您定义的其他路由及其顺序吗?可能是链接是基于另一个路由定义构建的。@FloatLeft,只需确保如果您有任何其他类似的路由,首先是限制性更强的路由,然后是更一般的路由。hi dbaseman。在问题的末尾添加了前面的路线。但是你说得对,“NewCertificates”路由是最后声明的。你可以包括你定义的其他路由,以及它们的顺序吗?可能是链接是基于另一个路由定义构建的。@FloatLeft,只需确保如果您有任何其他类似的路由,首先是限制性更强的路由,然后是更一般的路由。hi dbaseman。在问题的末尾添加了前面的路线。但是,您是对的,“NewCertificates”路由是最后声明的。“NewCertificates”是最后定义的路由。我已经编辑了问题以显示前面的路线。我猜URL是从其中一个构建的,但是你怎么知道是哪一个呢?使用路由调试器,Luke!“新证书”是最后定义的路由。我已经编辑了问题以显示前面的路线。我猜URL是从其中一个构建的,但是你怎么知道是哪一个呢?使用路由调试器,Luke!
@Html.RouteLink("Click Here",
// route name
"NewCertificates",
// route attributes
new { controller = "Quote", area = "NewQuote", date = "20121219", id = "acme" })