开发者

asp.net mvc2 Hw do I use Actionlink to jump from root straight to details page

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 { r开发者_如何学编程eturn "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?


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜