This question is locked. New answers and comments are not allowed.
I got this error when I try to add a new record to my grid, at the final is the source code
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
|
Source File: c:\Desarrollo\srojas\codigo\Maga\Maga\MagaSeguridadUI\Views\Grupos\Index.aspx Line: 43
Stack Trace:
|
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
View:
<% Html.Telerik().Grid(Model) .Name("Grid") .DataKeys(keys => { keys.Add(g => g.GrupoID); }) .ToolBar(commands => commands.Insert()) .Columns((IEnumerable<GridColumnSettings>)ViewData["Columns"]) .DataBinding(dataBinding => dataBinding.Server() .Select("Index", "Grupos") .Insert("Crear", "Grupos") .Update("Editar", "Grupos") .Delete("Eliminar", "Grupos")) .CellAction(cell => { // "DataItem" is the Order object to which the current row is bound to if (cell.Column.Title == "Estado" && cell.DataItem.Estado != null) { //Set the background of the entire row if (cell.DataItem.Estado.EstadoID == 2) cell.HtmlAttributes["style"] = "color:#CC0000;"; else cell.HtmlAttributes["style"] = "color:green;"; } }) .DetailView(perfilesDetailView => perfilesDetailView.Template(g => { %> <% Html.Telerik().Grid(g.Perfiles) .Name("Periles_" + g.GrupoID) .DataKeys(keys => { keys.Add(p => p.PerfilID); }) .Columns(columns => { columns.Bound(p => p.Aplicacion.Nombre); columns.Bound(p => p.Estado); columns.Bound(p => p.Nombre); columns.Bound(p => p.Descripcion); }) .CellAction(cell => { // "DataItem" is the Order object to which the current row is bound to if (cell.Column.Title == "Estado" && cell.DataItem.Estado != null) { //Set the background of the entire row if (cell.DataItem.Estado.EstadoID == 2) cell.HtmlAttributes["style"] = "color:#CC0000;"; else cell.HtmlAttributes["style"] = "color:green;"; } }) .Pageable(settings => settings.Style(GridPagerStyles.NextPreviousAndNumeric)) .Sortable() .Render(); %> <% } )) .RowAction(row => { if (row.Index == 1) { row.DetailRow.Expanded = true; } }) .Pageable(settings => settings.Style(GridPagerStyles.NextPreviousAndNumeric)) .Sortable() .Filterable() .Groupable() .Editable(editing => editing.Mode(GridEditMode.InLine)) .Resizable(resizing => resizing.Columns(true)) .Render(); %>Controller:
public ActionResult Index() { var columns = new[] { new GridColumnSettings { Member = "Aplicacion", Width = "130px" }, new GridColumnSettings { Member = "Estado", Width = "130px", }, new GridColumnSettings { Member = "Nombre", Width = "130px" }, new GridColumnSettings { Member = "Descripcion", Width = "300px" }, new GridCommandColumnSettings { Commands = { new GridEditActionCommand(), new GridDeleteActionCommand() }, Width = "180px", Title = "Acciones" } }; ViewData["Columns"] = columns; ViewData["aplicaciones"] = serviciosGrupos.getAplicaciones(); ViewData["estados"] = serviciosGrupos.getEstados(); return View(serviciosGrupos.getGrupos()); }Thank you