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
Grid
This is a migrated thread and some comments may be shown as answers.
mikel
Top achievements
Rank 1
mikel asked on 08 Jul 2014, 02:19 PM
Hi, my code is the following

VIEW

@(Html.Kendo().Grid(Model) // Bind the grid to the Model property of the view
             .Name("Usuarios")
             .AutoBind(true)             
             .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))
            .Filterable()
            .Pageable()
            .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
                       .Ajax()                
                        .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"))
                       .PageSize(5)
                   )
                   .Events(e => e.Remove("grid_remove").Edit("editar"))
 
   )

Controller

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);
        }


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


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
0
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.

Regards,
Atanas Korchev
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
mikel
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or