ASP.NET MVC 3 RESTful Routing: RouteData must contain an item named Action?
Asked Answered
H

1

6

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?

Heine answered 26/1, 2011 at 20:17 Comment(0)
I
2

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.

routes.MapRoute("Default", "{controller}/{action}/{id}",
            new
            {
                controller = "Home",
                action = "Index",
                id = UrlParameter.Optional
            });

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:

MyController/Details/{MyItemId}
Interlard answered 19/8, 2013 at 19:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.