Hi, my code is the following
VIEW
Controller
JAVASCRIPT
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
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