Link to home
Start Free TrialLog in
Avatar of xtremereality
xtremerealityFlag for United Kingdom of Great Britain and Northern Ireland

asked on

asp.net mvc folder organization

Hi all,
I'm new on asp.net mvc 2.0. I have a simple question that seems to be a bit silly but acutally I don't know how to resolve this little issue.
MVC is driven by action rather than pages.
The default routing should be: controller/action/id
An example can be: http://www.foo.com/home/dosomething

What if I want to organize things in a different way?
Let's say for example I want my url like this:
http://www.foo.com/en/home/doSomething
or
http://www.foo.com/us/home/results/doSomething

What to do in this case?

Thanks
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

I think you meant was selecting the page based on Culture in ASP. If that is what you meant, go through this link
http://msdn.microsoft.com/en-us/library/bz9tc508.aspx
You need to map your own routes.

In your global ASAX file

add

routes.MapRoute("home_example","{country}/{controller}/{action}", new {controller = "Home", action = "DoSomething");

and create a method on your home controller

public ActionResult DoSomething(string country)
{
}

when ever you use /us/home/dosomething or /uk/home/dosomething the above method should be called with the relevant value in the country parameter.

the sky's the limit in how you use this, but remember that there is a potential performance penalty if it all gets too complex and there are loads of mapped routes.
Avatar of xtremereality

ASKER

Thanks James my question is not necessary related with localization but more about routing in general,
If I'm understanding correctly, if I want this route:

http://foo.com/firstpart/secondpart/controller/action the only thing should be create this routes

routes.MapRoute("home_example","{firstpart}/{secondpart}/{controller}/{action}", new {controller = "Home", action = "DoSomething");

Is that correct?
If yes, this should not affect the real folder structure right? I mean I should have on VS this organization:
Controllers:
---------------->HomeController.cs
Views:
---------------->Home
------------------------->Index.aspx

and NOT

Controllers:
---------------->firstpart
---------------------------->secondpart
--------------------------------------------->HomeController.cs

And same thing with the Views?
ASKER CERTIFIED SOLUTION
Avatar of jamesbaile
jamesbaile
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial