Kendo UI TreeListDataSource Read () only works when run locally

I have a Kendo TreeList with its data source defined as

    var ds = new kendo.data.TreeListDataSource({
                    transport: {
                        read: {
                            url: "/Home/Read/",
                            type: "POST",
                            dataType: "json"
                        }},
                     schema:...
                     }

      

My controller read method:

[HttpPost]
public string Read()
{
    log.Info("Start read()");
    var vm = vmHelper.GetClientOrgListViewModel();
    var json = new JavaScriptSerializer().Serialize(vm.FacilityList);
    log.DebugFormat("json read returned: {0}", json);
    return json;
 }

      

Everything works fine as long as I run locally through VS, but once I deploy to our staging server, the Read () transport code never gets executed. I am getting 500 errors. Pressing F-12 to view requests in IE shows error 500

enter image description here

Any ideas or suggestions on why it works locally but not on the server and how to fix this issue?

+3


source to share


1 answer


Try to build your url using @Url.Action("Read", "Home")

var ds = new kendo.data.TreeListDataSource({
                transport: {
                    read: {
                        url: '@Url.Action("Read", "Home")',
                        type: "POST",
                        dataType: "json"
                    }},
                    schema:...
                }

      

If your javascript code is in a javascript file you won't be able to use the razor helpers. In this case, I'll add it to the list of urls that are stored in the layout file. Like this:



<script type="text/javascript">
    var Configuration;
    (function (Configuration) {
        var urls = {
            Read: '@Url.Action("Read", "Home")'
        }
        Configuration.url = urls;
    })(Configuration || (Configuration = {}));
</script>

      

Then just use it like:

transport: {
    read: {
        url: Configuration.url.Read
    }
}

      

+1


source







All Articles