Asp.net mvc 4 中间参数的ASP.NET MVC URL路由
我有一个名为Quote的控制器,它有一个需要requestId参数的索引方法。URL显示为这样Asp.net mvc 4 中间参数的ASP.NET MVC URL路由,asp.net-mvc-4,asp.net-mvc-routing,Asp.net Mvc 4,Asp.net Mvc Routing,我有一个名为Quote的控制器,它有一个需要requestId参数的索引方法。URL显示为这样 /Quote/{requestId}. /Quote/{requestId}/ApplicantInfo. 此外,我还有一个名为applicationInfo的方法,它专门用于报价和路线 /Quote/{requestId}. /Quote/{requestId}/ApplicantInfo. 但是当我使用Url.Action助手时 @Url.Action("Index","Quote
/Quote/{requestId}.
/Quote/{requestId}/ApplicantInfo.
此外,我还有一个名为applicationInfo的方法,它专门用于报价和路线
/Quote/{requestId}.
/Quote/{requestId}/ApplicantInfo.
但是当我使用Url.Action助手时
@Url.Action("Index","Quote",new { requestId = {requestId}})
它给了我一个
/Quote/ApplicantInfo?requestId={requestId}
路线不正确
显然,我可以手动创建URL字符串,但在我放弃之前,我想知道我是否遗漏了什么,例如对URL.Action
方法的覆盖,该方法将输出正确的URL
短暂性脑缺血发作
路线
我可以做类似的事情 路线 在
Global.asax.cs
或覆盖路由的位置定义路由
routes.MapRoute(
"Organization_default",
"{controller}/{requestId}/{action}",
new {
controller = "home",
action = "index",
requestId = "default",
id = UrlParameter.Optional
}, null);
控制器
看法
如果你在这里做所有的路线,你能在RouteConfig中给我看一下你的RegisterRoutes方法吗?谢谢,这让我达到了我需要的地方。
@{
ViewBag.Title = "Index";
var value = ViewData["value"];
}
<h2>Stackoverflow @value</h2>
@Html.ActionLink("Click Here",
"question", "StackOverflow", new { requestId ="Link" }, new{ @id="link"})
public override void RegisterArea(AreaRegistrationContext context)
{
//..custom route definition
}