I want to create a textbox with pre-defined possible values but I ended up with getting an error:
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
I try to use Token Input script (http://loopj.com/jquery-tokeninput/) but I failed to read data from the database. I'm working with .NET MVC.
Here's my method (in Model) to read data:
public List<CRMClientsModel> CRMClientsModel() {
var sqlConnect = DbConnectHelper.GetDbInstance<SqlConnection>();
var query = string.Format("SELECT CompanyName,Id from Company");
return sqlConnect.Query<CRMClientsModel>(query).ToList();
}
And here the part of controller responsible for conversion of data to JSON format
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;
Then in View it's called by
<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>