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

Foreign Key Column doesn't render a DropDownList

4 Answers 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Walter
Top achievements
Rank 1
Walter asked on 23 Apr 2013, 03:32 AM
Hi, I have been in this problem for too long. The Foreign Key Column doesn't render a DropDownList, instead of that, it renders an <input>. I don't know why. I've been through many forums but without success. Please help me. I have the following structure.

The model and view:
public class ProcesoEvaluacionDTO
    {
        [ScaffoldColumn(false)]
        public int ID { get; set; }
 
        [Required]
        [MaxLength(200)]
        public string Nombre { get; set; }
 
        [DisplayName("Fecha de cierre a evaluadores")]
        [Required]
        [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
        public string FechaCierre { get; set; }
 
        [Required]
        [UIHint("GridForeignKey")]
        [DisplayName("Autorizado por")]
        public int AutorizadorID { get; set; }
 
        public ProcesoEvaluacionDTO() { }
}
public class ColaboradorDTO
    {
        public string NombreCompleto { get; set; }
 
        public int ID { get; set; }
 
        public ColaboradorDTO() { }
 
    }
@{
    IList<ColaboradorDTO> colaboradores = ViewBag.colaboradores;
    SelectList lista = new SelectList(colaboradores, "ID", "NombreCompleto");
}
 
@(Html.Kendo().Grid<ProcesoEvaluacionDTO>()
            .Name("ProcesosDeEvaluacionGrid")
            .Columns(columns =>
                {
                    columns.ForeignKey((p => p.AutorizadorID), lista);
                    columns.Bound(p => p.Nombre);
                    columns.Bound(p => p.FechaCierre);
 
                    columns.Command(command => {
                        command.Edit();
                        command.Destroy();
                    }).Width(300);
                }
            )
            .ToolBar(toolbar => toolbar.Create())
            .Editable(editable => editable
                .Mode(GridEditMode.PopUp)
            )
            .Pageable(paper => paper.Refresh(true))
            .Filterable()
            .Sortable()
            .Scrollable(w => w.Height(330))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(20)
                .ServerOperation(false)
                .Events(events => events.Error("error_handler"))
                .Model(model => { model.Id(p => p.ID); })
                .Create(update => update.Action("EditingInline_Create", "ProcesoEvaluacion"))
                .Read(read => read.Action("EditingInline_Read", "ProcesoEvaluacion"))
                .Update(update => update.Action("EditingInline_Update", "ProcesoEvaluacion"))
                .Destroy(update => update.Action("EditingInline_Destroy", "ProcesoEvaluacion"))
            )
        )
Also, GridForeignKey.cshtml is in the correct place ~/Views/Shadres/EditorTemplates. I really don't know why an <input> appears. I've even tried to write my own custom editor template but I've got the same error. Help please.

4 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 24 Apr 2013, 08:32 AM
Hi Walter,

 
From the provided information it's not clear for us what is the exact reason for this behavior. For convenience I created small demo based on the provided information and attached it to the current thread - could you please check it and let me know how it differs from your real setup?

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ASAP Developer
Top achievements
Rank 1
answered on 19 Nov 2013, 05:25 PM
Hi Vladimir,
The solution you provided works fine for edit update but it doesn't work for add new item. It's displays a blank entry on add. Please fix the solution and post again.

Thanks,
Nitesh

0
ASAP Developer
Top achievements
Rank 1
answered on 19 Nov 2013, 05:53 PM
just fyi i changed my id from integer to string then it's working but i don't know if that's how it should be done
0
Vladimir Iliev
Telerik team
answered on 21 Nov 2013, 10:41 AM
Hi,

Could you please clarify what exactly it's not working on your side? The project is working as expected on our side as seen in this screencast

Regards,
Vladimir Iliev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Walter
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
ASAP Developer
Top achievements
Rank 1
Share this question
or