- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的预订 Controller
有以下代码
public ActionResult Index(string id, string name)
{
return View();
}
和我的routeConfig
有下面的路由映射
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Search",
url: "{controller}/{location}/{checkIn}/{checkOut}/{no}",
defaults: new { controller = "Search", action = "Index", location = UrlParameter.Optional, checkIn = UrlParameter.Optional, checkOut = UrlParameter.Optional, no = UrlParameter.Optional }
);
routes.MapRoute(
name: "booking",
url: "{controller}/{action}/{id}/{name}",
defaults: new { controller = "Booking", action = "Index", id = UrlParameter.Optional, name=UrlParameter.Optional }
);}
但是当我访问页面 http://localhost:59041/booking/index/1/libin
时,两个参数都返回 null
。
最佳答案
see this book
As your application becomes more complex you are likely going to register multiple routes. When you do this its important that you consider the order that that you register them. When the routing engine attempts to locate a matching route, it simply enumerates the collection of routes and it stops enumerating as soon as it find a match.
Add a comment This can cause plenty of problems if you’re not expecting it. Let’s look at an examples where this can be a problem:
routes.MapRoute(
> "generic", // Route name
> "{site}", // URL with parameters
> new { controller = "SiteBuilder", action = "Index" } // Parameter defaults );
>
> routes.MapRoute(
> "admin", // Route name
> "Admin", // URL with parameters
> new { controller = "Admin", action = "Index" } // Parameter defaults );
上面的代码片段注册了两条路线。第一条路线
contains a single placeholder segment and sets the default value of the controller parameter to SiteBuilder. The second route contains a single constant segment and sets the default value of the controller parameter to Admin.
Both of these routes are completely valid, but the order in which they are mapped may cause unexpected problems because the first route matches just about any value entered, which means that it will be the first to match
http://example.com/Admin and since the routing engine stops after finding the first match, the second route would never get used.
So, be sure to keep this scenario in mind and consider the order in which you define custom routes.
你应该先写预订路线
routes.MapRoute(
name: "booking",
url: "{controller}/{action}/{id}/{name}",
defaults: new { controller = "Booking", action = "Index", id = UrlParameter.Optional, name=UrlParameter.Optional }
);}
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Search",
url: "{controller}/{location}/{checkIn}/{checkOut}/{no}",
defaults: new { controller = "Search", action = "Index", location = UrlParameter.Optional, checkIn = UrlParameter.Optional, checkOut = UrlParameter.Optional, no = UrlParameter.Optional }
);
关于c# - MVC4 RouteConfig 参数返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15127776/
鉴于以下 .ts @RouteConfig([ { path: '/', name: 'root', redirectTo: ['Home'] }, { path:
我在设置 RouteConfig 文件以接受可选记录 ID 作为 URL 的一部分时遇到问题,如下例所示。 http://localhost/123 (used while debugging loc
我正在使用 Entity Framework 开发 C# ASP.NET MVC 项目。 我正在尝试使用 RouteConfig.cs 更改 url 路径 首先代码是这样的 public class
给定路由配置 @RouteConfig([ new Route({ path: '/app/index.html', name: 'default', redirectTo: ['/View1
我正在尝试按照本教程进行操作: https://angular.github.io/router/getting-started 为什么 AppController.$routeConfig 未定义?
我是 MVC 的新手,正在尝试构建我的第一个网站。我无法正确设置我的 RouteConfig 文件。我有 2 个规则适用于不同的 ActionResults。但是,只有其中一个可以正常工作。如果 Ge
最近我不得不更新我的 mvc web 应用程序,以便系统的基本实体以不同的文字显示在 UI 中。 让我们说 以前我有:“容器” 现在我被要求制作它:“Ships” 按照约定映射的 url:mysite
我的预订 Controller 有以下代码 public ActionResult Index(string id, string name) { return View(); } 和我的ro
我试图在我的 MVC 应用程序中“捕获所有”500 和 404 错误,但我似乎无法掌握需要什么,即使在阅读了所有文章和问题之后也是如此。 Web.config (这允许 500 个错误转到 ~/Vie
我正在尝试使用 ngdocs 和 grunt 记录我的 Angular WebApp。我想知道有没有一种方法可以记录路由配置,因为我觉得我的 WebApp 路由系统相当复杂,它的文档部分需要一些注意。
我正在尝试在我的 Angular2 应用程序中使用 RouteConfig。现在,我似乎无法找出我做错了什么。 我的 App 组件正在使用 router-outlet 东西,但它不起作用。 我创建了一
我认为我引用了我的解决方案中的三个文件,但我遇到了这 3 个错误 Global.asax.cs 名称“RouteConfig”在当前上下文中不存在 我错过了什么?谢谢:) using System;
我知道我可以在我的 MVC 应用程序的 RouteConfig 中更改路由: routes.MapRoute(name: "epage", url: "view/SpecificURL", defau
我正在构建一个使用 Angular 2 和纯 JavaScript 的应用程序,但我找不到任何关于如何将 RouteConfig 用于 JavaScript(不是 ts)的示例。 任何人都可以给我一个
我从 @vue/cli $> vue create my-project 创建了一个新的 vue 项目,激活了 Typescript 选项和路由器选项,并使用 $>vue add vue-next 升
我正在努力学习 Adam Freeman 的书“ASP .NET MVC”。在本书中有一章作者建议将路由放入特殊配置文件App_Start/RouteConfig.cs。它看起来不错,但我正在尝试在
我正在尝试使用 v1.4 中的 Angular 新路由器。我正在使用 typescript 。当我尝试编译时,出现以下错误。 Property '$routeConfig' does not exis
@RouteConfig 似乎已从 angular2 2.0.0-rc.1 中消失,@RouteConfig 在 @angular/router-deprecated 包中,同上在网站上记录的 api
关闭。这个问题需要debugging details .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 去年关闭。 Improve this question
这是 createStackNavigator({...}) 的工作代码块, 带有 initialRouteName 的 block 被注释掉。 const navigator = createSta
我是一名优秀的程序员,十分优秀!