开发者

ASP MVC Routing

now this is probably an stupid question but i'm new to mvc and can't seem to get i开发者_高级运维t working.

Here is what i would like to be able to do with the urls/routes:

1) www.domain.com/name/home/index

2) www.domain.com/home/index

where both the home controllers are seperate controllers and the name part will very but all must go to the same controller and the name should be an param for all the actions in there.

Is this at all possible? Thanks for your help.


This might not be the answer you're looking for, but I think that it would be more usual to see

www.domain.com/home/index
www.domain.com/home/index/name

My initial thinking was that an overloaded Index action method would make sense, but Daniel pointed out that this not allowed (at least not in the manner I suggested).

Updated answer...

Your Index action method could take a string name argument, and your routes would need to contain something like

routes.MapRoute(
    "Default",
    "{controller}/{action}/{name}",
    new { controller = "Home", action = "Index", name = "" }

In your action method a quick null check will tell you whether a name was included in the URL or not.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜