0

I am working on an ASP.Net MVC 5 application that has lot of ajax calls using jquery post as well as Kendo UI DataSource. I have a problem previously with relative urls which are working when I run the project from VisualStudio under IIS Express where the URL does not have site name (ex. http://localhost:22332/ ) and It stopped working once I deployed this to test because of site name in the url (http://orgname.com/SiteName/).

I have resolved this by setting "base" in my _Layout.cshtml page like this.

<base href="~/" />

Everything was fine until I ran into issue with one ajax call on IE9.

My Ajax call is like this:

$.post("Controller/Method")
when I am on the page http://localhost:36380/Controller/New, the above jquery post is submitted to http://localhost:36380/Controller/Method in Chrome, IE10 and IE 11, which is what is expected.

But in IE 9 it is being submitted to http://localhost:36380/Controller/New/Controller/Method

value of base is same in all the browsers which is "/" for localhost.

Is there a different behavior that I need to handle for IE9? This post is in a js file. If I can use ASP.Net MVC helper from a js file that can solve my problem too. Any suggestions?

user3731783
  • 718
  • 1
  • 7
  • 31
  • 1
    you should really be using `@Url.Action` whenever possible – JamieD77 Jul 29 '15 at 19:25
  • I love to. But my ajax calls are in a js file. I cant find an easier way to do that. There is a suggestion on SO http://stackoverflow.com/questions/9922041/use-seprate-js-file-and-use-url-helpers-in-it-with-asp-net-mvc-3-and-razor-view . As I have many Url's thats my last option. – user3731783 Jul 29 '15 at 19:28
  • 1
    is this getting called on click event? are you calling a function? can you pass in the url you want to post to? can you add a `data-post-url` attribute somewhere to reference? – JamieD77 Jul 29 '15 at 19:36
  • @JamieD77 This is part of a function which is being called from a kendo validation. I am not familiar with data-post-url. Is it related to html5 data attributes? My problem is only with IE9 and below. – user3731783 Jul 29 '15 at 20:44
  • yeah it's just a way to add attributes in html5. kendo caused me a ton of headaches but i'm not familiar with this issue. – JamieD77 Jul 29 '15 at 20:51
  • 1
    Always use `@Url.Action()` so your urls are generated correctly. If the function is in a separate script, add the url as a `data-` attribute to the element - e.g. ` –  Jul 29 '15 at 22:59

0 Answers0