TokenInput + Uncaught TypeError: Cannot read property 't

TokenInput + Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

本文关键字:property read Cannot Uncaught TypeError TokenInput      更新时间:2023-09-26

我想创建一个文本框与预定义的可能值,但我最终得到一个错误:

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

我尝试使用令牌输入脚本(http://loopj.com/jquery-tokeninput/),但我未能从数据库读取数据。我正在使用。net MVC。

这是我的方法(在模型中)读取数据:

   public List<CRMClientsModel> CRMClientsModel() {   
        var sqlConnect = DbConnectHelper.GetDbInstance<SqlConnection>();
        var query = string.Format("SELECT CompanyName,Id from Company");
        return sqlConnect.Query<CRMClientsModel>(query).ToList();
   }

这里是控制器负责将数据转换为JSON格式的部分

        CRMLogic Logic = new CRMLogic();
        CRMModel Model = new CRMModel();
        List<CRMClientsModel> Clients = Logic.CRMClientsModel().ToList();
        List<CRMClientViewModel> ClientsVM = Clients.Select(a => a.ToViewModel<CRMClientViewModel>()).ToList();
        Model.CRMClientsModel = Clients;
        CRMViewModel ViewModel = new CRMViewModel();
        ViewModel.CRMClientsModel = ClientsVM;
        JavaScriptSerializer jsonSerialiser = new JavaScriptSerializer();
        string json = jsonSerialiser.Serialize(ClientsVM);
        ViewModel.jsonproject = json;

然后在View中被

调用
<script type="text/javascript">
    $(window).ready(function () {
        @*var item = @Html.Raw(Model.jsonproject)
            alert(item)*@
        $("#inputproject").tokenInput(@Html.Raw(Model.jsonproject),
        {
            theme: "facebook", minChars: 0
        });
    });
</script>

明白了。原来这个错误是由于缺少"propertyToSearch"造成的。类似问题如下:jQuery-tokeninput failed: "未定义的吗?