Url.Action for mvc3 application located in subdirectory

I deployed the mvc3 application on the web. How to add virtual directory name to Url.Action () method?

for example: my application is located in mydomain.com \ app

now that i do

Url.Action returns action = "/ Home / Create", but I want action = "/ app / Home / Create".

What to do?

+6
source share
4 answers

You do not need to do this. If your application is correctly deployed to IIS in a virtual directory (say App ), then the Url.Action("Create", "Home") helper Url.Action("Create", "Home") will generate /app/home/Create , which is the correct URL.

+7
source

Map the route ( NOTE : this route should appear before the default route)

  context.MapRoute( name: "app", url: "app/{controller}/{action}/{id}", defaults: new { controller = "Test", action = "Index", id = UrlParameter.Optional } ); 

Then use Url.Action like this (should give you / application):

 @Url.Action("Index", "Test") 

You can find the routes in the Global.asax.cs file.

+1
source

It seems that what you are trying to do is create an AREA. MVC supports the use of Area to further organize the controllers and actions in your application.

For more information, see this MSDN article: http://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx

0
source

Finally, I use Url.Content ("~ / Home / Create"), which returns the entire URL located in the main or subdirectory.

0
source

All Articles