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

ForeignKeyColumn the combobox for the foreingkey is not not shown

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
diego
Top achievements
Rank 1
diego asked on 31 Jul 2012, 03:39 PM
hello
I'm new to kendo and was testing to see if buy the product while I'm making examples to see if I can use

I have a problem. I'm trying to do the  ForeignKeyColumn example but canĀ“t  get the combobox when running
it show me a textbox (where should be the combo for my foreingkey) and 
I can edit it and change the id and grabs fine the data.    but I need a combo and i know something  is
 missing but can figure what

can you help please? 

My View

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.CiudadViewModel>()
    .Name("Grid")    
    .Columns(columns => {        
        columns.Bound(p => p.id);
        columns.ForeignKey(p => p.empresa, (System.Collections.IEnumerable)ViewData["employees"], "id", "descripcion");        
        columns.Bound(p => p.descripcion);      
    })    
    .ToolBar(toolBar => toolBar.Save())
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable()
    .Sortable()
    .Scrollable()
    .Filterable()
    .DataSource(dataSource => dataSource        
        .Ajax()         
        .Batch(true)
        .ServerOperation(false)
        .Events(events => events.Error("errorHandler"))
        .Model(model => { 
            model.Id(p => p.id);
            model.Field(p => p.id).Editable(false);                
        })
        .Read(read => read.Action("ForeignKeyColumn_Read", "Home"))
            .Update(update => update.Action("ForeignKeyColumn_Update", "Home"))       
    )
)

MY VIEW MODEL

public class CiudadViewModel
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int id { get; set; }

        public string descripcion { get; set; }

        public int empresa { get; set; }

        [UIHint("Empresas"), Required]
        public EmpresaViewModel Empresa { get; set; }
    }

MY CONTROLLER 

 public ActionResult GridForeingKey()
        {
            PopulateEmployees();
            return View();
        }

        private void PopulateEmployees()
        {
            ViewData["employees"] = new EFDbContext().Empresas
                        .Select(e => new EmpresaViewModel()
                        {
                            id = e.id,
                            descripcion = e.descripcion
                        })
                        .OrderBy(e => e.descripcion);              
        }

        public ActionResult ForeignKeyColumn_Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(SessionClientOrderRepository.All().ToDataSourceResult(request));
        }

    public class SessionClientOrderRepository
    {
        public static IEnumerable<CiudadViewModel> All()
        {
            IEnumerable<CiudadViewModel> result = HttpContext.Current.Session["ciudad"] as IEnumerable<CiudadViewModel>;
            if (result == null)
            {
               HttpContext.Current.Session["ciudad"] = result = new EFDbContext().Ciudades
                    .Select(o => new CiudadViewModel
                    {
                        id = o.id,
                        descripcion = o.descripcion,
                        
                        empresa = o.Empresa ,
                        Empresa = new EmpresaViewModel
                        {
                            descripcion = o.descripcion,
                            id = o.id
                        }
                    }).ToList();
            }
            return result;
        }
    } 

1 Answer, 1 is accepted

Sort by
0
Emo
Top achievements
Rank 1
answered on 14 Aug 2012, 10:05 AM

Hello Diego,

I had the same problem. Solved it by adding EditorTemplates (got the whole floder and contents from the examples) to the Shared views folder and added the folder to the solution.

Regards

Tags
Grid
Asked by
diego
Top achievements
Rank 1
Answers by
Emo
Top achievements
Rank 1
Share this question
or