views:

68

answers:

1

I have some javacsript code looking something like below. Notice how it makes a ajax call to "/ContollerName/ActionName" with some parameters. This works fine as long as the application is deployed on a site root in IIS. But if I deploy it on a virtual directory the path will point all the way back to the site root and it will fail.

$.get("/ControllerName/ActionName", { foo: _bar, foo2: $(titleRow).attr("id"),
            Direction: direction
        }, function(data, success) {
            if (eval(data).Result == _successEnum) {
                successfulCallback();
            } else {
                failCallback(errorMessage, eval(data).LogPath);
            }

        }, "json");

How can I make it so it can be deployed both on site root level and on a virtual directory.

Both the below should basically work. I use ASP.NET MVC.

+1  A: 

Use Url.Action as the first parameter.

// link to a controller 
Url.Action("Home");
// link to an action 
Url.Action("Home", "Index");
Daniel A. White
Aha! Didn't know I could use it to get the path just the controller. Just what I needed. Thanks.
Riri