开发者

MVC3 MapRoute, how to

开发者 https://www.devze.com 2023-04-01 19:36 出处:网络
I am looking at creating some new rout开发者_如何学运维es within my MVC3 application. What I want is a route that will allow me to produce:

I am looking at creating some new rout开发者_如何学运维es within my MVC3 application. What I want is a route that will allow me to produce:

{clientname}/{controller}/{action}/{id}

Where I am unsure is whether or not I should make use of the object defaults parameter.


You could add the following route definition:

routes.MapRoute(
    "ClientRoute",
    "{clientname}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

Because clientname is at the beginning it is a compulsory value. It must always be specified and cannot be empty.

For example if you generate an anchor:

@Html.ActionLink("link text", "Foo", new { clientname = "bar" })

it would produce the following output:

<a href="/bar/Home/Foo">link text</a>
0

精彩评论

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