0

I've looked for this for a while and the solutions look like they should work, it appears I'm doing it wrong.

I created an area for administering the CMS side called "manage" so if you go to:

/Manage/Vinyard

it will give you a list of vinyards to manage using VinyardController built with the CRUD scaffold.

On the "front end" I have a browse controller and another VinyardController for viewing the details of a vinyard.

So someone goes to

/Browse/Vinyard

it gives them a list of Vinyards, they click on one (here's the problem) I want it to go to

/Vinyard/NameOfVinyard

The route that I have is:

      routes.MapRoute(
            "Vinyard",
            "Vinyard/{Name}",
            new { controller = "VinyardController", action = "Details", area="root"}
            );

Which is above the default route. Details is the method that displays the Vinyard details.

the HTML.actionlink I'm using is:

 @Html.ActionLink(item.Name, "Details", "vinyard" ,new { name = item.VinyardId, area="root" })

for some reason the a tag that's returned is: /Browse/Details?Length=7

On top of that when I try to browse to /vinyard/1 it gives me a 404.

Thanks for your help!

Update: If I browse to /vinyard/details/1 it works properly, except that I want it to eschew the /details/ part.

Snowburnt
  • 6,523
  • 7
  • 30
  • 43

2 Answers2

1

Use this overload

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    Object routeValues,
    Object htmlAttributes
)

So change your code to

 @Html.ActionLink(item.Name, "Details", "vinyard" ,
                 new { name = item.VinyardId, area="root" },null)
Shyju
  • 214,206
  • 104
  • 411
  • 497
  • That gave me just /browse/ for all of my entries. For some reason it's not differentiating between the different items other than the link name. – Snowburnt Jul 27 '12 at 17:08
0

Fixed it. Working with Shyju's modified action link, but I also removed the area property and had to fix up the map routing for it to work right.

My global.ascx now looks like this:

        routes.MapRoute(
            "Vinyard",
            "Vinyard/{id}",
            new { controller = "Vinyard", action = "Details", id=UrlParameter.Optional},
            new[] { "MyNameSpace.Controllers" }
            );

The two problems were: my controller name needed to be "Vinyard" not "VinyardController" and I needed to add the name space here and in my area route registration since I was using the same class names in both areas.

Snowburnt
  • 6,523
  • 7
  • 30
  • 43