views:

47

answers:

3
+1  Q: 

ASP MVC Routing

Hi, now this is probably an stupid question but i'm new to mvc and can't seem to get it 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.

A: 

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.

Richard Ev
You can't overload actions in ASP.NET MVC, except by differing both method signature and HTTP verbs.
Daniel Schaffer
@Daniel: You are quite right. I have updated my answer.
Richard Ev
A: 

Thanks for your replies,

First off, name is probably a bad example, customer would have been better.

See it as this: each customer will have there own home page but there is also an general home page for the website its self, where customers can sign up to the services we will be offering. Now if an custumer wants to go to the service the have signed up for, they can go there using there own url like: www.domain.com/customer/home/index and continue from there on to lets say www.domain.com/customer/account/change. etc. all those pages would be the same for all different customers but i need to supply specific information on it for each customer like there logo etc. for that i would like to have the customer given to each action.

hopes this clarifies it a bit what i want to do. And hopefully this is possible or there is a better approuch for this.

Richard
Please don't add answers to reply - use comments or update your question.
Daniel Schaffer
A: 

I would like to do that Daniel, but i don't see an edit link or an comment link. I must be blind?

Richard
It looks like you're re-registering a new account every time you come back. You need to log into this account: http://stackoverflow.com/users/328007/richard
Daniel Schaffer