or
public JsonResult GetCascadeCountries() { return Json(_db.Countries.Select(c => new {CountryId = c.Id, CountryName = c.CountryName }), JsonRequestBehavior.AllowGet); }
@(Html.Kendo().ComboBox() .Name("Countries") .Placeholder("Select a country") .DataTextField("CountryName") .DataValueField("CountryId") .DataSource(source => { source.Read(read => { read.Action("GetCascadeCountries", "Index"); }); }) )
if (elt.types[0] == 'country') { var countriesComboBox = $('#Countries').data("kendoComboBox"); alert($('#Countries_input').data()); var selectItem = function (dataItem) { //dataItem argument is a ComboBox data item. return dataItem.Text == elt.long_name; } countriesComboBox.select(selectItem); }
<div id="userGrid" data-role="grid" data-columns='[{ "field": "Name", "title": "Name"}, { "field": "Group", "title": "Group"}]' data-filterable='true' data-navigatable='true' data-pageable='true' data-groupable='true' data-sortable='true' data-bind="source: userDataSource"></div>and the DataSource is being set in javascript like this:
public ActionResult ListUsers([DataSourceRequest] DataSourceRequest request) { return Json(GetUsers().ToDataSourceResult(request)); }
@using Kendo.Mvc.UI;@model IEnumerable<OTIS.AppServ.Shared.ViewModels.ddlOptions>@(Html.Kendo().AutoComplete() .Name("TEST") .Filter("startswith") .DataTextField("DisplayName") .BindTo(Model) .Events(e => e .Change("autocomplete_change") ) .Placeholder("Select Customer...") .HtmlAttributes(new {@class = "filter"}) )<input class="filter" id="@ViewBag.ControlId" type="hidden" /><script> //$("#TEST").attr("id", '@ViewBag.ControlId' + '_org'); function autocomplete_change() { var hiddenInput = $('#' + '@ViewBag.ControlId'); var autoContainer = $("#" + 'TEST').data("kendoAutoComplete"); var result = $.grep(autoContainer.dataSource.data(), function (itemInArray, itemIndex) { return itemInArray.DisplayName == autoContainer.value(); } ); //alert(result[0].Id) hiddenInput.val(result[0].Id); }</script>[ChildActionOnly] public ActionResult Customers() { List<ddlOptions> viewModel = new List<ddlOptions>(); viewModel = _manageDDLsAppServ.GetCustomersDDLViewModel(_currentCompanyId).ToList(); ViewBag.ControlId = "customerIdFilter"; return PartialView("_ddlOptionsAutoComplete", viewModel); }@{ Html.RenderAction("Customers", "ManageDDLs", new { area = "Shared" }); }Compilation ErrorDescription: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree typeSource Error:Line 8: .DataTextField("DisplayName")Line 9: .BindTo(Model)Line 10: .Events(e => e
.Change("autocomplete_change"))Line 11: .Placeholder("Select Customer...")Line 12: .HtmlAttributes(new {@class = "filter"})@using Kendo.Mvc.UI;@model IEnumerable<OTIS.AppServ.Shared.ViewModels.ddlOptions>@(Html.Kendo().AutoComplete() .Name(ViewBag.ControlId) .Filter("startswith") .DataTextField("DisplayName") .BindTo(Model) .Events(e => e
.Change("autocomplete_change")) .Placeholder("Select Customer...") .HtmlAttributes(new {@class = "filter"}) )<script> function autocomplete_change() { var autoContainer = $("#AutocompleteId").data("kendoAutoComplete"); var result = $.grep(autoContainer.dataSource.data(), function (item) { item.Text == autoContainer.value(); }); } </script>@{ Html.RenderAction("Customers", "ManageDDLs", new { area = "Shared" }); }[ChildActionOnly] public ActionResult Customers() { List<ddlOptions> viewModel = new List<ddlOptions>(); viewModel = _manageDDLsAppServ.GetCustomersDDLViewModel(_currentCompanyId).ToList(); ViewBag.ControlId = "customerIdFilter"; return PartialView("_ddlOptionsAutoComplete", viewModel); }I have a question about duplicate static window content script initialization.
Let's see an example:
I have a KendowUI Window with static content:
@Html.Kendo().Window().Name("Window").Content(@<div>
<script type="text/javascript">
$(document).ready(function () {
alert('It\'s me!');
});
</script>
</div>).Visible(false).Modal(true).Title("Test").Draggable(false)
So when I am opening page with provided code I see two alerts.
Please help me to find different solution except provided below:
<script type="text/javascript">
$(document).ready(function () {
alert('It\'s me!');
});
</script>
@Html.Kendo().Window().Name("Window").Content(@<div>
</div>).Visible(false).Modal(true).Title("Test").Draggable(false)
This is very important for me for initializing KendoUI controls inside of static window content.
<fieldset class="form-list"> <ol> <li> <label>Project *</label> @(Html.Kendo().DropDownList() .Name("1Project") .DataTextField("DisplayName") .DataValueField("ProjectID") .DataSource(source => { source.Read(read => { read.Action("ProjectList", "ReturnMail"); }); }) ) </li> <li> <label>Name Address 1</label> <input type="text" id="1NameAddress1" class="k-textbox" /> </li> <li> <label>Name Address 1</label> <input type="text" id="1NameAddress2" class="k-textbox" /> </li> <li> <label>Name Address 1</label> <input type="text" id="1NameAddress3" class="k-textbox" /> </li> <li> <label>Name Address 1</label> <input type="text" id="1NameAddress4" class="k-textbox" /> </li> <li> <label>Name Address 1</label> <input type="text" id="1NameAddress5" class="k-textbox" /> </li> <li> <label>City</label> <input type="text" id="1City" class="k-textbox" /> </li> <li> <label>State</label> <input type="text" id="1State" class="k-textbox" maxlength="2" /> </li> <li> <label> </label> <button id="SearchAddressButton" class="k-button primary">Search</button> </li> </ol> </fieldset>
Controller Code:public JsonResult ProjectList(string userName = "") { if (userName == "") userName = Request.ServerVariables["AUTH_USER"]; List<ProjectModel> proj = ProjectModel.AllProjects(); return Json(proj); }