Kendo ui 剑道UI下拉列表不接受JSON数据?
使用Kendo DropdownList for MVC,尝试确定DropdownList不接受此数据的原因Kendo ui 剑道UI下拉列表不接受JSON数据?,kendo-ui,html-select,kendo-asp.net-mvc,Kendo Ui,Html Select,Kendo Asp.net Mvc,使用Kendo DropdownList for MVC,尝试确定DropdownList不接受此数据的原因 @(Html.Kendo().DropDownList() .Name("CompanyList") //The name of the DropDownList is mandatory. It specifies the "id" attribute of the widget. .DataTextField("Table") .
@(Html.Kendo().DropDownList()
.Name("CompanyList") //The name of the DropDownList is mandatory. It specifies the "id" attribute of the widget.
.DataTextField("Table")
.DataValueField("COM_NAME")
.DataSource(source =>
{
source.Custom() // Read(read =>
.Type("json")
.Transport(transport =>
{
transport.Read("GetallCompanies", "Home");
})
.ServerFiltering(true); //If true, the DataSource will not filter the data on the client.
})
.SelectedIndex(0) //Select the first item.
)
SQL操作中的原始数据具有以下格式:
“{\'Table\':[{\'ORG\'ID\':265498,\'COMPORGID\':239597,\'COM\'NAME\':\'ABC Rentals\',{\'ORG\'ID\':164929,\'COMPORGID\':239698,\'COM\'NAME\':\'Asbury Machine Shop\'}”
已引用了和其他SO示例。将JSON放入验证器工具,表示其格式正确
在页面中,下拉列表有一个左大括号,{作为顶部项,单击时有几十个:未定义
DataTextField被称为“Table”,因为JSON数组中有“Table”,但它被设置为COM_NAME
[HttpGet]
public JsonResult GetallCompanies()
{
var ddx = CompInfo.GetAllCompanies(); //returns dataset
string thedata = JsonConvert.SerializeObject(ddx);
return Json(thedata, JsonRequestBehavior.AllowGet);
}
我认为在返回到客户端之前,您不需要在
ddx
上使用SerializeObject
以及Json
方法。您可以尝试将GetAllCompanys
更改为:
[HttpGet]
public JsonResult GetallCompanies()
{
var ddx = CompInfo.GetAllCompanies(); //returns dataset
//string thedata = JsonConvert.SerializeObject(ddx);
return Json(ddx);
}
Json
方法摘要:
创建将指定数据对象序列化为JSON的Microsoft.AspNetCore.Mvc.JsonResult对象
试试这个:
JsonConvert.SerializeObject
行注释掉
之后。选择索引(0)
):
.Schema(Schema=>Schema.Data(“表”))
ddx
从CompInfo.GetAllCompanies()
得到了什么?最初它返回的是以“Table\”开头的JSON,但根据答案,我将其更改为去掉Serialized对象,因此现在它返回一个带有单个表的数据集[0]和许多行。是的,将其更改为现在它将数据集返回到剑道DDL,仍然没有显示任何内容,但一个新的行为是,单击DDL将导致控制器方法被重新读取,以前没有这样做。我在返回的Json()上有一个调试断点行,因此现在它的读数与我在单击事件中预期的一样;但不会显示任何数据。我怀疑由于属性的原因,读取
可能会在每次单击时被触发。它似乎以任何方式读取。但仍然没有显示数据,是否有任何方法将调试信息发送到控制台,说明此控件拒绝显示数据的原因?是否它需要一些函数来遍历行并建立列表?只要您正确分配了.DataTextField
和.DataValueField
,并且数据的格式可以接受,那么就不需要对数据进行操作。实际上,有一个很好的Chrome扩展名,您可以使用它来检查t您的剑道控制属性(包括数据源)。已使用Inspector工具,已修改并以各种格式发送数据,包括字符串、JSON或dataset。更改了.DataTextField和.DataValueField,并已从数组名称复制/粘贴。无拼写错误。Inspector显示空数组,数据:数组[0]=null。从不在简单的DropDownList中显示任何数据。Json(ddx)。不接受“table”,但确实看到“Tables”。我正在尝试此操作以及表[0]。行。还将尝试使用来自示例的简单DropDownList数据强制转换字符串,并传递该字符串以查看发生了什么。