0

Why is:

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

Generating this:

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

When my route is like this.

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

and action is like this in the WidgetsController

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

The route should look like this:

http://localhost:2227/widgets/v1/divisions?eventid=36295
Mike Flynn
  • 22,342
  • 54
  • 182
  • 341
  • You `@Url.Action()` does not match that route. What are you expecting the url to look like? –  Dec 13 '14 at 06:17
  • I guess that would of been smart to add, `http://localhost:2227/widgets/v1/divisions?eventid=36295` – Mike Flynn Dec 13 '14 at 06:36
  • You have also shown `ActionResult Event()` (did you mean `ActionResult divisions()`? And did you want both `eventid` and `slug` to be query strings (`/widgets/v1/divisions?eventid=36295&slug=MySlug`) or `/widgets/v1/divisions/36295/MySlug` –  Dec 13 '14 at 06:41
  • Yes wrong copy and paste content – Mike Flynn Dec 13 '14 at 06:43
  • If I remove slug = "event" from the route it works correctly. Not sure why. – Mike Flynn Dec 13 '14 at 06:48
  • Remove `slug = "event"` in the route definition (or change the route to `widgets/v{version}/{action}/{eventid}/{slug}` –  Dec 13 '14 at 06:49
  • Done, if you make that the answer ill update it accordingly – Mike Flynn Dec 13 '14 at 06:55

1 Answers1

0

Remove slug = "event" from the route definition (you do not have a placeholder in the url so the route is not matched)

Alternatively change the url parameter to

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

which would generate (assuming version = 1, eventid = 36295 and slug = "MySlug")

/widgets/v1/divisions/36295/MySlug