DataSource relative URLs?

10 posts, 0 answers
  1. Tony H
    Tony H avatar
    3 posts
    Member since:
    May 2012

    Posted 21 Nov 2012 Link to this post

    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?
  2. Chris
    Chris avatar
    25 posts
    Member since:
    Apr 2011

    Posted 28 Dec 2012 Link to this post

    I am also interested in this, any solutions please?
  3. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Dec 2012 Link to this post

    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!
  4. Chris
    Chris avatar
    25 posts
    Member since:
    Apr 2011

    Posted 28 Dec 2012 Link to this post

    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?
  5. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Dec 2012 Link to this post

    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!
  6. Chris
    Chris avatar
    25 posts
    Member since:
    Apr 2011

    Posted 28 Dec 2012 Link to this post

    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?
  7. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Dec 2012 Link to this post

    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!
  8. Chris
    Chris avatar
    25 posts
    Member since:
    Apr 2011

    Posted 28 Dec 2012 Link to this post

    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".
  9. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 28 Dec 2012 Link to this post

    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!
  10. Chris
    Chris avatar
    25 posts
    Member since:
    Apr 2011

    Posted 02 Jan 2013 Link to this post

    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.
Back to Top