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

2 posts, 0 answers
  1. Chad
    Chad avatar
    29 posts
    Member since:
    Nov 2012

    Posted 18 Dec 2012 Link to this post

    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);
            }

  2. Chad
    Chad avatar
    29 posts
    Member since:
    Nov 2012

    Posted 18 Dec 2012 Link to this post

    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.
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top