8

I have deployed a mvc3 application in web. How can i add Virtual directory name in Url.Action() method ?

for eg : my application is in mydomain.com\app

now when i do

Url.Action returns action="/Home/Create" but what i want is action = "/app/Home/Create".

What should be done ?

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
Nitin Kabra
  • 3,146
  • 10
  • 43
  • 62

4 Answers4

8

You shouldn't need to do that. If your application is properly deployed in IIS inside a virtual directory (say App) then the Url.Action("Create", "Home") helper will generate /app/home/Create which is the correct url.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

Map a route (NOTE: this route has to 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 /app):

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

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

Allov
  • 1,308
  • 1
  • 13
  • 23
0

It appears 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.

Please see this MSDN arcticle for more info: http://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx

Glenn Ferrie
  • 10,290
  • 3
  • 42
  • 73
0

Finally I am using Url.Content("~/Home/Create") which returns the whole URL whether hosted on main or sub directory.

Nitin Kabra
  • 3,146
  • 10
  • 43
  • 62