views:

19

answers:

1

On a root page in my project I have a number of different country services gathered by category all on one page. The Category is the "Index" page in the View folder in a separate area, and the particular service is the "Details" view. I want the user to be able to jump straight past the category in the (in this case China) area to that particular services detail.

I have this:

<%=Html.ActionLink("More Info", "Details", "ParticularChinaServiceControllerName", new { area = "China" }, new { id = p.ID })%>

but the framework will not pick up the id.

The route is registered as: public override string AreaName { get { return "China"; } }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "China_default",
            "China/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

Can someone show me how to make this work correctly?

+1  A: 

Change your controller name from "ParticularChinaServiceController" to "ParticularChinaService" and see if that fixes the issue.

Wait, that last argument:

new { id = p.Id }

...is actually the htmlAttributes argument, and will apply that id as an attribute of the hyperlink generated in html. Change the previous argument to this:

new { area = "China", id = p.Id }

And drop the last argument (unless you need to apply some specific client side attributes).

Matthew Abbott
no, unfortunately not, that's just a substitute name for demo purposes of this site instead of the real one, but thanks for that
Paul Connolly
Answer updated, see if that helps.
Matthew Abbott
Yes, i tried that already but it just creates "/Details?Length=27" which makes me think that I am still short one little piece in that actionlink statement.
Paul Connolly
But! viola! I took what you said, swapped it, dropped in a "null as the attribute parameter like so: new { id = p.ID, area = "China" },nulland it worked, thanks a lot.
Paul Connolly
final statement reads: <%=Html.ActionLink("More Info", "Details", "ParticularChinaServiceControllerName", new { id = p.ID, area = "China" },null)%>
Paul Connolly

related questions