This is a migrated thread and some comments may be shown as answers.

DataSource relative URLs?

9 Answers 618 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Tony H
Top achievements
Rank 1
Tony H asked on 21 Nov 2012, 03:34 PM
Hi, I am trying to put a relative URL against a read property in a dataSource but when the page is rendered, the dataSource always seems to be prefixing the URL with a '/' making it look from the root.  Any way to get around this please?

9 Answers, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 28 Dec 2012, 03:19 PM
I am also interested in this, any solutions please?
0
Atanas Korchev
Telerik team
answered on 28 Dec 2012, 03:36 PM
Hello,

 The solution is to output the URL from server-side code. The actual implementation depends on the server-side technology.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 28 Dec 2012, 03:44 PM
Hi,

Thanks for the reply.

I'm doing it using Kendo UI without the MVC helpers (coding JS only) and when the page URL is "/Sales" and the URL I put on the read property fro a data source is simply "Orders", I would expect it to request "/Sales/Orders" rather than "/Orders", which is what is actually being requested.  

I know this is not a server side issue because I can see in the Chrome Developer tools that "/Orders" is the URL being requested when I fetch the data using the data source when using a URL of just "Orders".

I can only interpret your response as meaning to use server side code to specify the URL which, on rendering, outputs the absolute URL for Kendo DataSource to use, is this correct?  Are you saying that Kendo DataSource cannot interpret relative URLs specified directly in JS code?
0
Atanas Korchev
Telerik team
answered on 28 Dec 2012, 03:49 PM
Hi,

 Kendo DataSource doesn't do anything to interpret relative URLs. The browser interprets relative urls (you can try with a regular hyperlink to see for yourself).

 You should use Url.Action in ASP.NET MVC to get the proper url:

 dataSource: {
        transport: { 
              read: {
                  url: '@Url.Action("action", "controller")'
              }
        }
 }

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 28 Dec 2012, 04:03 PM
Hi,

Sorry, I don't think we are understanding each other.  Firstly, I cannot use Url.Action, because I don't always know the controller AND this code will be in a seperate JS file (which means it won't get parsed by the server).  To put the issue simply, I would just like to be able to specify the following in a JS file:

// code
transport: {
read: 'Orders'
}
// more code

This is so that where-ever I want to use this in my MVC application I can include this script file and it will show orders, for example, I might want to include in one or more of the following URLs:

http://mydomainname.com/Sales (http://mydomainname.com/Sales/Orders)
http://mydomainname.com/Purchase  (http://mydomainname.com/Purchase/Orders)
http://mydomainname.com/Work  (http://mydomainname.com/Work/Orders)

And for each one, the datasource should use the URL specified in brackets above, however, it currently does not.  If I specify the url as I have above in the JS code, each time I go to one of these pages, the requested URL is http://mydomainname.com/Orders.  I hope you understand now?
0
Atanas Korchev
Telerik team
answered on 28 Dec 2012, 04:06 PM
Hi,

 I understand you. I am not sure how this can be done though. How do you implement the same for regular hyperlinks?

Kind regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 28 Dec 2012, 04:12 PM
Hi,

If my page URL is "http://mydomainname.com/Sales" and I put a hyperlink as <a href='Orders'>Go to orders</a>, when clicked, this will go to "http://mydomainname.com/Sales/Orders".  

However, what I am saying is that the DataSource widget seems to request "http://mydomainname.com/Orders" when I just put "Orders" as a relative URL for the read property when used in a page with the URL "http://mydomainname.com/Sales".
0
Atanas Korchev
Telerik team
answered on 28 Dec 2012, 04:21 PM
Hi,

I tried this in a jsbin demo: http://jsbin.com/oxohut/1/edit The data source makes a request to http://jsbin.com/oxohut/1/Orders. 

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Chris
Top achievements
Rank 1
answered on 02 Jan 2013, 11:49 AM
Thanks for the reply and the demo, after investigating this some more I found that it is to do with using MVC, if an index page is requested, the browser treats the controller as the page name and therefore sets the base url to the path prior to the controller name, i.e. "http://mydomainname.com/Sales" gets converted in MVC to "http://mydomainname.com/Sales/Index" and the index page is returned.  I assumed that the browser would know this but of course it doesn't, the browser assumes that Sales is the page not the path and therefore sets the base url to "http://mydomainname.com/".  Therefore, when it makes the request to the datasource, it requests "http://mydomainname.com/Orders" and not "http://mydomainname.com/Sales/Orders" like I was hoping.

To fix this I've just outputted the meta tag <base href="http://mydomainname.com/Sales" /> and the requests now work as expected.  I hope this helps other people that come across this issue and I apologise for incorrectly thinking this was a Kendo issue.
Tags
Data Source
Asked by
Tony H
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or