Undefined Values in Kendo Dropdownlist

3 posts, 0 answers
  1. Goldfy
    Goldfy avatar
    6 posts
    Member since:
    Oct 2013

    Posted 05 Nov 2013 Link to this post

    Hi, I am using Telerik's dropdownlist in my MVC application View. I am facing two problems:

     1) When I run my application, I find every value of kendo dropdownlist is "Undefined".
       This is the code for my View:
          @model IEnumerable<EulenMgrKendoUIMvcApplication.Dominio.Tablas.DelegacionProductoUsuario>

         @(Html.Kendo().DropDownListFor(d=>d)

                .Name("IdDelegacionProductoDrpDwn").HtmlAttributes(new { @style = "font-size:12px" })
                .DataTextField("IdDelegacionProducto")
                .DataValueField("IdDelegacionProducto")
                .BindTo((System.Collections.IEnumerable)ViewData["IdDelegacionProducto"]))

       This is my controller, where I populate the dropdownlist:
       public class DelegacionProductoUsuarioController : Controller
             public ViewResult List()
            {
                IEnumerable<DelegacionProductoUsuario> delegaciones = DelegacionProductoUsuario.GetAll();
              PopulateDelegacionProducto();
                return View(delegaciones);
            }
           private void PopulateDelegacionProducto()
            {
                List<Int64> IdDelegacionProductoList = new List<Int64>();
                foreach( DelegacionProductoUsuario d in DelegacionProductoUsuario.GetAll()){
                    IdDelegacionProductoList.Add(d.IdDelegacionProducto);
                }
                ViewData["IdDelegacionProducto"] =IdDelegacionProductoList ;
            }
    }

         I am debugging the application and the controller is passing to the view the proper values,so I don't understand why it doesn't show them.
     
    2) Second problem: I insert this Dropdownlist in one of the columns of a kendo grid with no success. In it's place it appears a common label. Here is the code for
     my Grid, I mark in Bold the column where I try to show  my dropdownList:
          @(Html.Kendo().Grid(Model)
              .Name("Grid")
              .Columns(columns=>
              {
                columns.Bound(d => d.BorradoLogico).Title("Borrado logico");
                columns.Bound(d => d.FTick).Title("Ftick");
               columns.Bound(d => d.IdDelegacionProducto).Title("IdDelegacionProducto").EditorTemplateName("IdDelegacionProductoDrpDwn");    
                columns.Bound(d => d.IdUsuario).Title("IdUsuario");
             })
    MAY SOMEBODY HELP ME PLEASE?
  2. Daniel
    Admin
    Daniel avatar
    2118 posts

    Posted 07 Nov 2013 Link to this post

    Hello,

    The enumeration passed to the dropdonwlist should consist of objects that contain properties with the specified names e.g.

    ViewData["IdDelegacionProducto"] = DelegacionProductoUsuario.GetAll();
    or
    List<object> IdDelegacionProductoList = new List<object>();
    foreach( DelegacionProductoUsuario d in DelegacionProductoUsuario.GetAll()){
        IdDelegacionProductoList.Add(new
        {
            IdDelegacionProducto = d.IdDelegacionProducto
        });
    }
    ViewData["IdDelegacionProducto"] = IdDelegacionProductoList;

    As for the second issue - what editing mode are you using? If you are using popup editing then the EditorForModel helper and you should use the UIHint attribute on the model property to specify the editor name. If you are not using popup editing then verify that you have correctly included the editor template and that the name is the same. Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Goldfy
    Goldfy avatar
    6 posts
    Member since:
    Oct 2013

    Posted 07 Nov 2013 Link to this post

    Thanks Daniel but the code you write to solve my first problem is exactly the same I write in my post. 
    On regard to my second problem, I am doing  what you advice, it is marked Bold.  

       SO CAN ANYBODY ELSE HELP ME PLEASE?
Back to Top