.net - ASP.NET 路由没有被正确的映射击中

  显示原文与译文双语对照的内容
0 0

为什么:

@Url.Action("Divisions","Widgets", new {version = 1, eventId = Model.Event.Id, slug = Model.Event.Slug})

正在生成:

http://localhost:2227/widgets/divisions?version=1&eventid=36295&slug=notifications

当我的路线是这样的时候。

 routes.MapRoute(
"DefaultWidget",
"widgets/v{version}/{action}",
 new { controller ="Widgets", action ="NotFound", version = 1, slug ="event"},
 new { version = @"d+" }
 );

而行动在WidgetsController中就像这样

 public virtual ActionResult Divisions(int version, int? eventId, string slug)
 {
 return GetDivisions(eventId, new WidgetEventViewModel(version));
 }

路由应如下所示:

http://localhost:2227/widgets/v1/divisions?eventid=36295
时间:原作者:6个回答

0 0

从路由定义中删除 slug ="event" ( 你在 url 中没有占位符,因此路由不匹配)

或者将url参数更改为

"widgets/v{version}/{action}/{eventid}/{slug}",

这将生成( 。假定版本= 1,eventid = 36295和 slug ="myslug"

/widgets/v1/divisions/36295/MySlug
原作者:
...