ambiguous bindto

5 posts, 1 answers
  1. Bart
    Bart avatar
    15 posts
    Member since:
    May 2014

    Posted 11 Feb Link to this post

    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.

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 15 Feb Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Bart
    Bart avatar
    15 posts
    Member since:
    May 2014

    Posted 15 Feb in reply to Daniel Link to this post

    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

  5. Answer
    Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 16 Feb Link to this post

    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
  6. Bart
    Bart avatar
    15 posts
    Member since:
    May 2014

    Posted 16 Feb in reply to Daniel Link to this post

    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.

Back to Top
UI for ASP.NET MVC is VS 2017 Ready