Kendo下拉列表产生TypeError:n.slice不是函数

lit*_*ude 11 asp.net asp.net-mvc c#-4.0 kendo-grid kendo-asp.net-mvc

我需要定义架构吗?如果是这样,那应该是什么样的?我对此的搜索似乎只出现了js解决方案,我正在寻找在editortemplate中定义它的语法.

共享/ editortemplate:

@(
Html.Kendo().DropDownList()
.Name("SearchFunction")
.DataTextField("SearchFunctionDesc")
.DataValueField("SearchFunctionCode")
.DataSource(source =>
    {        
        source.Read(read => { 
            read.Action("GetSearchFunctions", "User");
        });
    })
    .OptionLabel("--Select a Search Function--")
    .AutoBind(false)
)
Run Code Online (Sandbox Code Playgroud)

在控制器中:

    public JsonResult GetSearchFunctions([DataSourceRequest] DataSourceRequest request)
    {
        var searchFuncs = AdminService.GetSearchFunctions();
        DataSourceResult result = searchFuncs.ToDataSourceResult(request);
        return Json(result, JsonRequestBehavior.AllowGet);
    }
Run Code Online (Sandbox Code Playgroud)

然后我的Dapper db查询:

            var result = new List<SearchFunction>();
            using (var conn = new OracleConnection(DatabaseConnectionString))
            {
                conn.Open();
                string query = "select FUNCTION_ID, SEARCH_FUNCTION_CD, " +        
                        "SEARCH_FUNCTION_DESC, IS_ACTIVE " +
                         "from TBL_SEARCH_FUNCTIONS "; 
                result = conn.Query(query)
                    .Select(s => new SearchFunction
                    {
                        FunctionId = (int)s.FUNCTION_ID,
                        SearchFunctionCode = s.SEARCH_FUNCTION_CD,
                        SearchFunctionDesc = s.SEARCH_FUNCTION_DESC,
                        Active = s.IS_ACTIVE
                    }).ToList<SearchFunction>();
                conn.Close();
                return result;
            }
Run Code Online (Sandbox Code Playgroud)

pie*_*ove 27

像这样重写你的控制器方法:

public JsonResult GetSearchFunctions()
{
    var searchFuncs = cmsViewAdminService.GetSearchFunctions();
    return Json(searchFuncs, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)

这应该简化该方法,因为您不需要DataSourceRequest(如注释中提到的@CSharper).与网格不同,Kendo DropDownLists不需要DataSourceRequest类.这样,如果需要,可以从jQuery Ajax方法调用相同的JsonResult.