Friday, May 11, 2012

"The call is ambiguous between the following methods or properties" MVC 3 Telerik Drodownlist

While working on my project i suddenly got this error...


The call is ambiguous between the following methods or properties: 'Telerik.Web.Mvc.UI.Fluent.DropDownBuilderBase<Telerik.Web.Mvc.UI.DropDownList,Telerik.Web.Mvc.UI.Fluent.DropDownListBuilder>.BindTo(System.Collections.Generic.IEnumerable<Telerik.Web.Mvc.UI.DropDownItem>)' and 'Telerik.Web.Mvc.UI.Fluent.DropDownBuilderBase<Telerik.Web.Mvc.UI.DropDownList,Telerik.Web.Mvc.UI.Fluent.DropDownListBuilder>.BindTo(System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>)'

After spending few mints on tracking this issue i get it solved.This error comes when you DO NOT provide the data to the view from the Controller.  In my case here is the code that work for me.

Just provide all the things used in View like ViewBag,ViewData etc etc.

public ActionResult Index(FormCollection formValues)
        {
            var CountryList = GetCountryList();
            ViewBag.AllCountryList = CountryList ;

            return View();
        }

 @(Html.Telerik().DropDownList()
            .Name("ddlCountries")
            .ClientEvents(events => events
                          .OnChange("onDropDownListChange")
                          )
            .SelectedIndex(0)
            .BindTo(ViewBag. CountryList )
            .HtmlAttributes(new { style = string.Format("width:{0}px", 80) })
    )


Note: This solution work for me successfully. You may have to search more if you failed.

2 comments: