I use a <base href="@Url.Content("~")"> element in my pages so that I can reference URLs from JavaScript and they will still work even when the web app is installed in an IIS virtual directory, etc. vFor example I often using URLs like $.get('api/something/something'); and because of the <base> element it prefixes that value onto the .get requests that I make.
The problem is when using a relative url with the grid it does not work. I get the error: "Uncaught Error: Syntax error, unrecognized expression: #api/Policy/GetContracts"
What's the solution here and what are your recommendations?
Hello Michael,
Thank you for contacting Infragistics!
I have some questions concerning this matter. What is the URL you set to the DataSourceUrl of the igGrid? How is your “GetContracts” method setup? Have you tried using an Url.Action?
@Mike Peterson,
I'm using the jquery plugin directly so I don't think I'm suppsed to use the datasourceurl property but rather the datasource property. Also, I use the jquery grid plugin from a .js file as I think it's a bad idea to mix application logic with the html view meaning I can't use Url.Action to set the URL.
A slimmed down version of the code I'm using within a separate script file is essentially this:
$("#grid").igGrid({ dataSourceUrl: 'api/Policy/Contracts', autoGenerateColumns: false, columns: getColumnDefinitions(), height: 500, width: '100%'});
This causes an error to be thrown: Uncaught Error: Syntax error, unrecognized expression: #api/Policy/Contracts
What I was saying is that typically (in conjunction with using the <base> element that I mentioned above) I would expect from JS a request to be made to api/Policy/Contracts and the browser will transparently translate it into the prefix of the value in the <base> element + api/Policy/Contracts. In my case that is '/api/Policy/Contracts' (note there is now a slash prefix).
In my opinion, it is unexpected and incorrect behavior for the datasource to throw an error in this with a url like this. It is a very common pattern to use the base element the way I'm using it.
In the short term, is there a descent way to solve this problem while still using a URL of 'api/Policy/Contracts'?
Thank you for the update. I have done some further looking into this matter and when I have my url have proceding “/” it work, for example:
dataSourceUrl: "/Home/GetGridData",
Have you tried it formatted that way? What was the result?
I am following to see if the information provided has resolved this matter. If this isn’t the case please provide me with the answers to my questions.
Please let me know if I may be of further assistance with this matter.