简单的ASP.NET MVC路由问题
我的简单 MVC 应用程序中有两个页面,其中有两个定义的路线:
routes.MapRoute(
"Results", // Route name
"Results/{id}", // URL with parameters
new { controller = "Results", action = "Index",
id = "" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Main", action = "Index",
id = UrlParameter.Optional } // Parameter defaults
);
我需要仅使用产品 ID 加载结果页面,如下所示:[MyDomain...]/Results/12345。而且主页还使用以下路线向结果控制器执行 POST(使用 JQuery)进行更新:[MyDomain....]/Main/Update 以及数据包。当我只有“默认”路线时,这工作正常。但是当我添加其他“结果”路由时,所有更新的 POST 调用都失败。有什么想法我做错了吗???
多谢。
I have two pages in my simple MVC App with two defined routes:
routes.MapRoute(
"Results", // Route name
"Results/{id}", // URL with parameters
new { controller = "Results", action = "Index",
id = "" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Main", action = "Index",
id = UrlParameter.Optional } // Parameter defaults
);
I needed to have the results page load with just a product ID such as this: [MyDomain....]/Results/12345. But also the main page does a POST (using JQuery) to the Results Controller for updates using this route: [MyDomain....]/Main/Update along with a data bag. This works fine when I only have the "Default" route. But when I added the other "Results" route, all the POST calls to update are failing. Any ideas what I'm doing wrong???
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有尝试过这个,但应该可以完成你所需要的。不确定是否有“更好”的方法来实现它。
I didn't try this out, but should accomplish what you need. Not sure if there may be a "better" way to accomplish it.