This is a migrated thread and some comments may be shown as answers.
Undefined Values in Kendo Dropdownlist
2 Answers 98 Views
This is a migrated thread and some comments may be shown as answers.
Goldfy
Top achievements
Rank 1
Goldfy asked on 05 Nov 2013, 03:44 PM
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 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 07 Nov 2013, 10:51 AM
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!
0
Goldfy
Top achievements
Rank 1
answered on 07 Nov 2013, 11:37 AM
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?
Asked by
Goldfy
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Goldfy
Top achievements
Rank 1
Share this question
or