Jul 17, 2015, 1:26 PM
[OPEN] [#837] Object reference not set to an instance of an object when using GridPanel with Data annotation
This issue was previously reported here: http://forums.ext.net/showthread.php...on-not-working
The error is a NullReferenceException when using the GridPanel with data annotation:
View:
The error is a NullReferenceException when using the GridPanel with data annotation:
System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=App_Web_hllijq3o
StackTrace:
at ASP._Page_Views_OpenPayments_Index_cshtml.Execute() in g:\VisualStudio\Visual Studio 2013\Websites\BugExtNetDateFormat\BugExtNetDateFormat\Views\OpenPayments\Index.cshtml:line 171
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
at System.Web.WebPages.StartPage.RunPage()
at System.Web.WebPages.StartPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
InnerException:
The error occurs when [DateColumn(Format = "d")] is used in the model to annotate an SQL column.View:
@using Ext.Net;
@using Ext.Net.MVC;
@model IEnumerable<BugExtNetDateFormat.OpenPayment>
@{
ViewBag.Title = "Index";
var X = Html.X();
}
<h2>List</h2>
<p>
@(Html.X().ResourceManager())
@(X.GridPanel()
.ID("GridPanel1")
.Store(X.StoreForModel().ID("Store1")
.Sorters(X.DataSorter().Property("Licence_id").Direction(Ext.Net.SortDirection.ASC)))
.Icon(Icon.Table)
.Title("Licences")
.Width(900)
.Height(350)
.ColumnModel(
X.CommandColumn()
.Width(70)
.Commands(
Html.X().GridCommand()
.Text("Reject")
.ToolTip(t =>
{
t.Text = "Reject row changes";
})
.CommandName("reject")
.Icon(Icon.ArrowUndo)
)
.PrepareToolbar(t =>
{
t.Handler = "toolbar.items.get(0).setVisible(record.dirty);";
})
.Listeners(l =>
{
l.Command.Handler = "record.reject();";
}),
X.ColumnFor(Model, m => m.Date)
.ToBuilder<Column.Builder>()
.Flex(1)
.Editor(X.DateField().AllowBlank(false)),
X.ColumnFor(Model, m => m.Customer).ToBuilder<Column.Builder>()
.Flex(1)
.Editor(X.TextField().AllowBlank(true)),
X.ColumnFor(Model, m => m.Currency).ToBuilder<Column.Builder>()
.Flex(1)
.Editor(X.TextField().AllowBlank(true)),
X.ColumnFor(Model, m => m.Amount)
.ToBuilder<Column.Builder>()
.Flex(1)
.Editor(X.NumberField().AllowBlank(true))
)
.SelectionModel(X.CheckboxSelectionModel().Mode(SelectionMode.Multi))
.Plugins(X.FilterHeader())
.BottomBar(X.PagingToolbar().HideRefresh(true))
.DockedItems(
X.Toolbar()
.Dock(Dock.Bottom)
.Items(
X.Button()
.Text("Case Sensitive")
.EnableToggle(true)
.AllowDepress(true)
.ToggleHandler("var plugin = this.up('GridPanel1').filterHeader; plugin.caseSensitive = this.pressed; plugin.applyFilter();"),
X.Button()
.Text("Load Filters")
.Handler("loadFilter(this.up('GridPanel1').filterHeader);"),
X.Button()
.Text("Get Fields Values")
.ToolTip("Get Values of Fields")
.Handler("var values = Ext.encode(this.up('GridPanel1').filterHeader.getValue()); Ext.Msg.alert('Fields Values', values);"),
X.Button()
.Text("Get Filter Values")
.ToolTip("Get Filter Values of Grid")
.Handler("var filters = Ext.encode(this.up('GridPanel1').filterHeader.getFilterValues()); Ext.Msg.alert('Filter Values', filters);"),
X.Button()
.Text("Clear Filters")
.Handler("this.up('grid').filterHeader.clearFilter();"),
X.Button()
.Text("Sync")
.Icon(Icon.Disk)
.DirectEvents(de =>
{
de.Click.Url = Url.Action("HandleChanges");
de.Click.ExtraParams.Add(new Parameter
{
Name = "data",
Value = "this.up('GridPanel1').store.getChangedData()",
Mode = ParameterMode.Raw,
Encode = true
});
})
)
)
.Plugins(
Html.X().CellEditing()
)
.Listeners(l =>
{
l.AfterRender.Handler = "this.filterHeader.fields[0].setIconCls('#Magnifier')";
l.AfterRender.Delay = 10;
}))
}
}
</p>
Model:namespace BugExtNetDateFormat
{
using System;
using System.Collections.Generic;
public partial class OpenPayment
{
[ModelField(IDProperty = true, UseNull = true)]
[Field(Ignore = true)]
public int id { get; set; }
[ModelField(Ignore = true)]
public string PhantomId
{
get;
set;
}
public string Customer { get; set; }
//[Column(Text = "Payment Due")]
[DateColumn(Format = "d")]
public Nullable<System.DateTime> Date { get; set; }
public string Currency { get; set; }
public Nullable<decimal> Amount { get; set; }
public string Via { get; set; }
public string Notes { get; set; }
public Nullable<bool> Received { get; set; }
}
}
We have provided a sample VS2013 project on Google drive. Please see separate email.
Last edited by Daniil; Jul 17, 2015 at 4:35 PM.
Reason: [OPEN] [#837]