This is a migrated thread and some comments may be shown as answers.

AutoComplete Events in PartialView = "Cannot use a lambda expression..." Error

1 Answer 303 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Chad
Top achievements
Rank 1
Chad asked on 18 Dec 2012, 10:53 PM
Per the documentation I am trying to add Events to the autocomplete helper so I can lookup the value of the selected item (as seen in this post), but when doing so am getting the following error on line 10:
Compilation Error
 
Description: 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 type
 
Source 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"})
Here is the PartialView 
@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>
Call from View:
@{ Html.RenderAction("Customers", "ManageDDLs", new { area = "Shared" }); }
Controller:
[ChildActionOnly]
        public ActionResult Customers()
        {
            List<ddlOptions> viewModel = new List<ddlOptions>();
            viewModel = _manageDDLsAppServ.GetCustomersDDLViewModel(_currentCompanyId).ToList();
            ViewBag.ControlId = "customerIdFilter";
 
            return PartialView("_ddlOptionsAutoComplete", viewModel);
        }

1 Answer, 1 is accepted

Sort by
0
Chad
Top achievements
Rank 1
answered on 18 Dec 2012, 11:47 PM
Ahhh, my issue here was trying to use a dynamic name
.Name(ViewBag.ControlId)
If you just make this a fixed name, everything works ok. I will post a new question on how to pass in a .Name value.
Tags
AutoComplete
Asked by
Chad
Top achievements
Rank 1
Answers by
Chad
Top achievements
Rank 1
Share this question
or