ASP.NET MVC 3 RESTful 路由:RouteData 必须包含名为 Action 的项目?
我们正在使用 ASP.NET MVC Futures 项目 (Microsoft.Web.Mvc) 来使 MVC 3 应用程序能够使用 RESTful 路由。该应用程序在 MVC 1 及其相关的 System.Web.Mvc.Resources.dll 程序集下完美运行,具有相同的功能。
我们这样注册路由:
routes.MapResourceRoute("MyController", "{MyItemId}");
这应该给我们这样的路由:
/MyController
/MyController/{MyItemId}
/MyController/{MyItemId}/EditForm
/MyController/CreateForm
我们得到四个有效路由中的三个 - 该列表上的第二个 (/MyController/{MyItemId}) 返回错误:
Server Error in '/' Application.
The RouteData must contain an item named 'action' with a non-empty string value.
当我尝试附加 ?action 时=详细信息或向 URL 注入操作参数的其他方式,我收到 404 错误。看起来 Futures 代码中的 WebEnabledApi 属性发生了显着变化 - 其他人也遇到这些问题并有解决方案吗?
We are using the ASP.NET MVC Futures project (Microsoft.Web.Mvc) to enable an MVC 3 application to use RESTful routes. This application has been working perfectly under MVC 1 and its related System.Web.Mvc.Resources.dll assembly for the same functionality.
We are registering the routes as such:
routes.MapResourceRoute("MyController", "{MyItemId}");
Which should give us routes like:
/MyController
/MyController/{MyItemId}
/MyController/{MyItemId}/EditForm
/MyController/CreateForm
We get three of the four routes that are valid -- the second on that list (/MyController/{MyItemId}) returns an error:
Server Error in '/' Application.
The RouteData must contain an item named 'action' with a non-empty string value.
When I try appending ?action=Details or other ways of injecting an action parameter to the URL, I get 404 errors. It looks like the WebEnabledApi attribute in the Futures code changed significantly - anyone else having these issues, and have a solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认路由基于“controller/action/id”,因为您只传递 id 而不是操作,它会给您 404 错误。
我相信您正在尝试调用详细信息操作。
如果您确实在控制器上执行了操作,则使用默认路由可能会起作用:
The default route is based on "controller/action/id", as you're just passing the id and not the action, it will give you 404 error.
I believe you're trying to call the details action.
If you do have a action on the controller, using the default route might work: