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

Grid with Foreign Key Column Displaying Blank After Creation

1 Answer 71 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
mikel asked on 08 Jul 2014, 02:19 PM
Hi, my code is the following


@(Html.Kendo().Grid(Model) // Bind the grid to the Model property of the view
             .Columns(columns =>
                 columns.Bound(p => p.Id).Visible(false);
                 columns.Bound(p => p.Nombre).Width(300);
                 columns.Bound(p => p.Apellido1).Width(300);
                 columns.Bound(p => p.Apellido2).Width(300);
                 columns.Bound(p => p.Codusuario).Width(300);
                 columns.Bound(p => p.Fechacambiopassword).Width(300);
                 columns.Bound(p => p.Idperfil).Width(300);
                 columns.ForeignKey(p => p.Idperfil, (System.Collections.IEnumerable)ViewBag.Perfiles, "Id", "Descripcion").Width(300).EditorTemplateName("PerfilesDropDownList");
                 columns.Command(command => { command.Edit(); command.Custom("Eliminar").Click("grid_remove"); }).Width(200);
             .ToolBar(commands => commands.Create())
            .Sortable(s => s.SortMode(GridSortMode.SingleColumn))
            .Scrollable(scroll => scroll.Height("auto"))          
            .Editable(editable => editable.Mode(GridEditMode.PopUp).DisplayDeleteConfirmation(false).TemplateName("UsuariosEdicion").Window(w => w.Title("Editar Usuario").Width(700)))
            .DataSource(dataSource => dataSource
                        .Sort(sort => sort.Add("Apellido1").Ascending())
                       .Model(model => model.Id(p => p.Id))
                        .Create(create => create.Action("InsertarUsuario", "Account"))
                        .Read(read => read.Action("ObtenerUsuarios", "Account").Data("getAdditionalData"))
                       .Update(update => update.Action("ModificarUsuario", "Account"))
                       .Destroy(destroy => destroy.Action("EliminarPerfil", "Account"))
                       .Events(e => e.RequestStart("grid_mostrarspinner").RequestEnd("grid_ocultarspinner").Error("error"))
                   .Events(e => e.Remove("grid_remove").Edit("editar"))


public async Task<JsonResult> InsertarUsuario([DataSourceRequest] DataSourceRequest request, Usuarios usuario)
            if (ModelState.IsValid)
                Error error = await ServicioSeguridad.Current.InsertarUsuarioAsync(usuario);
            return Json(new[] { usuario }.ToDataSourceResult(request, this.ModelState));

public async Task<JsonResult> ObtenerUsuarios([ModelBinder(typeof(MyDataSourceRequestBinder))] MyDataSourceRequest request, FiltroBusquedaUsuarios filtrousuario)
            MyDataSourceRequest req = new MyDataSourceRequest
                Page = request.Page,
                Aggregates = request.Aggregates,
                Filter = request.Filter,
                PageSize = request.PageSize,
                Group = request.Group,
                Sort = request.Sort
            MyDataSourceResult usuarios = await ServicioSeguridad.Current.ObtenerUsuariosFiltrosAsync(req, filtrousuario, "");
            //Debug.WriteLine("total:" + usuarios.Total.ToString());
            DataSourceResult resultado = new DataSourceResult
                Data = usuarios.Data,
                Total = usuarios.Total,
                AggregateResults =null,
                Errors = null
            //Debug.WriteLine("Data:" + ((List<Usuarios>)resultado.Data).Count.ToString());
             Parse p = new Parse();
            DataSourceRequest requestKendo = p.ParseRequest(request.Page, request.PageSize, request.Sort, request.Group, request.Filter, request.Aggregates);
            //DataSourceResult resultado = usuarios.ToDataSourceResult(requestKendo);
            return Json(resultado, JsonRequestBehavior.AllowGet);

function rellenargrid() {
       var grid = $("#Usuarios").data("kendoGrid");
       //llama al read del grid

This code javascript is called from a button search.

When I insert a new record and press the button that calls the search function fetch of datagrid cell shows foreignkey column blank, when press F5 in the browser correctly displays the value in cell

Thanks in Advance

1 Answer, 1 is accepted

Sort by
Atanas Korchev
Telerik team
answered on 10 Jul 2014, 11:59 AM
Hello Daniel,

This isn't a known issue and we will need some additional details about it so we understand what is going on.
  1. Does the issue manifest itself after saving the new record?
  2. Is the foreign key field correctly set when the new record is saved? You can verify this by stepping with the debugginer within the InsertarUsuario method.
  3. What is the data returned by the ObtenerUsuarios method when you do the search? Does the new record contain the foreign key field properly set? Again this can be checked with the debugger.
  4. We've noticed that you are using a custom model binder (MyDataSourceRequestBinder) for the data source request. Does the problem occur when you use the default model binder?
  5. Can you show us how the PerfilesDropDownList partial view looks like?

Ideally you could attach a runnable version of your project which reproduces the problem. This will be the fastest way for us to determine the cause.

Atanas Korchev
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Asked by
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question