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

ambiguous bindto

4 Answers 1099 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Bart
Top achievements
Rank 1
Bart asked on 11 Feb 2016, 04:06 PM

Hi,

I'm trying to create a dropdown into a gridview, and I have tried lots op things.
the thing I'm stuck with now is this error

"The call is ambiguous between the following methods or properties: 'Kendo.Mvc.UI.Fluent.DropDownListBuilder.BindTo(System.Collections.Generic.IEnumerable<Kendo.Mvc.UI.DropDownListItem>)' and 'Kendo.Mvc.UI.Fluent.DropDownListBuilder.BindTo(System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>)'"

in the Bindto I have a list of items which I load from the viewbag.

But I can't get pass this error.
do U need to unreference something?
thank you.

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Feb 2016, 01:52 PM
Hi,

Could you provide the code that you are using for the dropdownlist and to add the ViewBag entry? The error indicates the ViewBag entry is not set or is set to null.
 
Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bart
Top achievements
Rank 1
answered on 15 Feb 2016, 02:03 PM

Hi Daniel,

I have changed the source now so the dropdownlist is static, but it's not as it should be off course.

what I had was the following
in shared views I have a folder with EditorTemplates and in it I have this template "StatusDdl.cshtml"

@using Kendo.Mvc.UI;
@model int
 
@(Html.Kendo().DropDownList()
    .Name("Status")
    .Value(Model.ToString())
    .SelectedIndex(0)
    .BindTo(ViewBag.StatusDdl)
    .HtmlAttributes(new { style = "width:250px" })
    .ValuePrimitive(true)
)
the controller looks as following:
public ActionResult Users_Read([DataSourceRequest]DataSourceRequest request)
        {
            List<UserStatus> UserStatus = db.UserStatus.ToList();
            ViewBag.StatusDdl = UserStatus;
 
 
            IQueryable<Users> users = db.Users;
            DataSourceResult result = users.ToDataSourceResult(request, user => new {
                Id = user.Id,
                UserId = user.UserId,
                Name = user.Name,
                Email = user.Email,
                Password = user.Password,
                Status = user.Status,
                //UserStatus = new Teunesen_Bestandsbeheer.Models.UserStatus()
                //{
                //    Id = user.UserStatus.Id,
                //    Status = user.UserStatus.Status
                //},
                Admin = user.Admin,
                Language = user.Language,
            });
 
            return Json(result);
        }
where ViewBag.StatusDdl is the past which is used in the view.

and the view itself looks like this.

  @(Html.Kendo().Grid<Teunesen_Bestandsbeheer.Models.Users>()
                  .Name("grid")
                  .Columns(columns =>
                  {
                  columns.Bound(c => c.Name).Title("Naam").HtmlAttributes(new { @class = "edit-col" });
                  columns.Bound(c => c.Email).Title("Email").HtmlAttributes(new { @class = "edit-col" });
                  //columns.ForeignKey(c => c.Status, (System.Collections.IEnumerable)ViewData["UserStatus"], "Id", "Status");
                  columns.Bound(c => c.Status).Title("Status").HtmlAttributes(new { @class = "lock-col" }).EditorTemplateName("StatusDdl").Width(270);
            columns.Bound(c => c.Admin).ClientTemplate(
      "<input type='checkbox' value='#= Id #' " +
          "# if (Admin) { #" +
              "checked='checked'" +
          "# } #" +
      "/>"
);

where the partialview is used as editor template.

The viewbag however is filled, that I'm sure of, but I think maybe I need to specify a type or something but I can't figure it out.

 

Regards

 

Bart

0
Accepted
Daniel
Telerik team
answered on 16 Feb 2016, 11:22 AM
Hi again,

From the code it seems that the ViewBag is populated in the DataSource Read action and not the action used to Render the View with the grid. Thus the ViewBag entry will not be available at the time the grid and its editors are rendered. Please try moving the code to set the ViewBag entry in the action that returns the View with the grid.

Regards,
Daniel
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Bart
Top achievements
Rank 1
answered on 16 Feb 2016, 12:13 PM

thnx,

That's it

User control like this

public ActionResult Index()
       {
           ViewData["UserStatus"] = db.UserStatus;
           var UserStatus = db.UserStatus.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Status }).ToList();
           ViewBag.StatusDdl = UserStatus;
           return View();
       }
and then in the view this
columns.ForeignKey(c => c.Status, (System.Collections.IEnumerable)ViewData["UserStatus"], "Id", "Status").EditorTemplateName("StatusDdl").Width(270);
and that was it.

Tags
DropDownList
Asked by
Bart
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Bart
Top achievements
Rank 1
Share this question
or