-1

I have the following route config in my mvc4 project:

routes.MapRoute(
            name: "single",
            url: "{controller}/{id}",
            defaults: new { controller = "Home", action = "Details" },
            constraints: new { id = @"^[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}$" }
        );

        routes.MapRoute(
            name: "singleCreate",
            url: "{controller}/{id}/{action}",
            defaults: new { controller = "GalleryImage", action = "Create" },
            constraints: new { id = @"^[0-9a-fA-F]{8}[-]?([0-9a-fA-F]{4}[-]?){3}[0-9a-fA-F]{12}$" }
        );

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

and now i would like to create a link to the route "singleCreate".

I've tried this:

@Html.ActionLink("Add Image", "Create", "GalleryImage", new { id = Model.Id }, null)

but this doesn't work as I expected. I get a Link without an action which looks like this:

/GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4

The link should be like this:

/GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4/Create

Has anyone already created such a link and can give me some suggestions? Thanks in advance.

tereško
  • 58,060
  • 25
  • 98
  • 150
DARKHalf
  • 63
  • 10

1 Answers1

2

Try this:

@Html.RouteLink("Add Image", "singleCreate", new { controller = "GalleryImage", action = "Create", id = Model.Id })
Fabio S
  • 1,124
  • 6
  • 8
  • I've tried that. Now I get a link to the wrong controller: http://localhost:4427/Gallery/cc66338c-6500-4967-8be9-a8a6948f22c4 – DARKHalf Aug 20 '13 at 14:59
  • Whats really surprising is when I User a different action for ActionLink the Action is correctly appended on the end of the link. I have to rename my view then but then everything works. I do not understand what goes wrong if I leave the views in original. – DARKHalf Aug 20 '13 at 15:01
  • Still no luck: /GalleryImage/cc66338c-6500-4967-8be9-a8a6948f22c4 – DARKHalf Aug 20 '13 at 16:04