0

I am at an ASP.NET MVC page located at the following address:

http://somedomain/someapp/Foo/Bar?param=val

I have a Foo controller and also a Bar controller. I need to call the Bar controller's DoSomething action and pass it along the parameters I already have in the current URL's query string:

http://somedomain/someapp/Bar/DoSomething?param=val

I can't just set the AJAX call's URL to "/Bar/DoSomething" because that takes me to the following address:

http://somedomain/Bar/DoSomething?param=val

I can't specify the entire URL, as this will vary depending on the deployment.

I'm assuming there's some way of doing this using MapRoutes that will achieve what I want and pass along the data as well.

3 Answers 3

1

Since you already have the url with parameters, you can do something like:

ResolveUrl("~/Bar/DoSomething?param=val");

Which would convert the given virtual url to an absolute url

Sign up to request clarification or add additional context in comments.

Comments

1

There is at least 3 possibilities :

1 - you can have a "global" variable in javascript where you set the value of the web application base and replace the "http://somedomain.com/someapp/" with the variable :

var liveString = "http://" + window.location.host;
if (liveString.indexOf('somedomain.com') > 0) {
    liveString = liveString + '/someapp';
} else if (liveString .indexOf('localhost') > 0) {
    liveString = liveString + '/localApp';
}

You can also have a link that yo get the url in jQuery :

<a id="link-id" href="<%Url.Action("ActionName", "ControllerName", new { param = val })%>" style="display:none;"></a>

var myUrlCall = $('#link-id').href;

You can also create an application at the root in IIS 7 using an other port or adding it in your host file so your url could look like : htttp://someapp.local, we use this last option since it's the one that better represent the live application.

Let me know if you need more help!

Comments

0

Check out Ajax.ActionLink You can specify the name of the controller there, and the code to be invoked on success, failure etc.

ASP.NET MVC 2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.