开发者

How should I add a static value to the end of a route using Url.Action (in ASP.NET MVC 3)?

开发者 https://www.devze.com 2023-02-13 01:28 出处:网络
I have this route: routes.MapRoute(null, \"Users/{id}/Summary\", new { controller = \"Users\", action = \"GetSummary\" });

I have this route:

routes.MapRoute(null, "Users/{id}/Summary", new { controller = "Users", action = "GetSummary" });

How can I specify this using a Url.Action?

I'm curren开发者_开发知识库tly using:

string path = Url.Action("Index", "Users", new { id = user.Id } ) + "/Summary";

Is there a cleaner approach?


Why are you using Index when the action is GetSummary?

string path = Url.Action("GetSummary", "Users", new { id = user.Id } );

You probably want to give your Route a name

routes.MapRoute("GetSummary", "Users/{id}/Summary", 
    new 
    {
        controller = "Users", 
        action = "GetSummary" 
    });


Does this not work?

 Url.Action("GetSummary", "Users", new { id = user.Id })

The routing engine should be able to turn that into the correct URL based on your routing tables.

0

精彩评论

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