gpt4 book ai didi

c# - Kendo UI TreeListDataSource Read() 仅在本地运行时有效

转载 作者:行者123 更新时间:2023-11-30 17:44:19 26 4
gpt4 key购买 nike

我有一个 Kendo TreeList,其数据源定义为

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

我的 Controller 的读取方法是:

[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;
}

只要我通过 VS 在本地运行,一切都很好,但是一旦我部署到我们的暂存服务器,就永远不会执行 Read() 传输代码。我收到 500 错误。在IE中按F-12查看请求显示500错误

enter image description here

关于为什么它在本地工作但在服务器上不工作以及如何解决这个问题有什么想法或建议吗?

最佳答案

尝试使用 @Url.Action("Read", "Home") 构建您的 URL>

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

如果您的 javascript 代码在 javascript 文件中,您将无法使用 Razor 助手。在这种情况下,我所做的是将它添加到我保留在布局文件中的 URL 列表中。像这样:

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

然后将其用作:

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

关于c# - Kendo UI TreeListDataSource Read() 仅在本地运行时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com