System.ArgumentException: JSON primitivo inválido: "EmptyRecord":"No records to display","GroupCaptionFormat":"{{:headerText}}: {{:key}} - {{:count}} ","GroupText":" item","True":"true","False":"false"}.
Html.EJ()
.Grid<TravelAccountability.Web.ViewModels.ExpenseTypesListViewModel>
("gridExpenseTypes")
.Locale(Culture)
.AllowTextWrap()
.AllowPaging().PageSettings(page => { page.PageSize(10); })
.AllowKeyboardNavigation(false)
.IsResponsive(true)
.EditSettings(
edit =>
{
edit.AllowAdding()
.AllowDeleting()
.AllowEditing()
.EditMode(EditMode.Normal);
}
)
.ClientSideEvents(
eve =>
{
eve
.ActionComplete("querycell")
.ActionBegin("begin")
.BeginEdit("beginedit")
.EndEdit("endEdit")
.EndAdd("endAdd");
}
)
.ToolbarSettings(
toolbar =>
{
toolbar.ShowToolbar()
.ToolbarItems(
items =>
{
items.AddTool(ToolBarItems.ExcelExport);
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
}
);
}
)
.AllowFiltering()
.FilterSettings(
filter => { filter.FilterType(FilterType.Excel); }
)
.Datasource(x => x.Json(Model.ExpenseTypes)
.InsertURL(Url.Action("SaveExpenseType", "Administration"))
.UpdateURL(Url.Action("UpdateExpenseType", "Administration"))
.RemoveURL(Url.Action("RemoveExpenseType", "Administration"))
.Adaptor(AdaptorType.RemoteSaveAdaptor))
.Columns(
col =>
{
col
.Field(c => c.ExpenseTypeID).IsPrimaryKey(true)
.Visible(false).Add();
col
.Field(c => c.Description).Priority(1).IsIdentity(true)
.ValidationRules(v => v
.AddRule("validationRequired", 0)
.AddRule("validationMax50", 50)
.AddRule("messages", "{required:'" + Resource.ExpenseTypesListViewModel_DescriptionValidation + "'}")
)
.Add();
col
.Field(c => c.FiscalAccount).Priority(2).EditType(EditingType.String)
.ValidationRules(v => v
.AddRule("validationRequired", 0)
.AddRule("validationMax8", 8)
.AddRule("messages", "{required:'" + Resource.ExpenseTypesListViewModel_FiscalAccountValidation + "'}")
)
.Add();
col
.Field(c => c.IsActive).Priority(3).Visible(true).EditType(EditingType.Boolean)
.Width("105px").HeaderTextAlign(TextAlign.Right).TextAlign(TextAlign.Center)
.Add();
col
.Field(c => c.IsDailyExpenseRate).Visible(false)
.Add();
col
.Field(c => c.CreatedOnString).Visible(false).EditType(EditingType.String)
.Add();
col
.Field(c => c.CreatorRE).Visible(false).DefaultValue(Model.CreatorRE)
.Add();
col
.Field(c => c.ModifiedOnString).Visible(false).EditType(EditingType.String)
.Add();
col
.Field(c => c.ModifierRE).Visible(false).DefaultValue(Model.ModifierRE)
.Add();
col
.Field(Resource.ExpenseTypeViewModel_Details).Priority(1)
.AllowEditing(false)
.AllowFiltering(false)
.Template("#actionColumnTemplateDetail")
.Width("120px")
.TextAlign(TextAlign.Center)
.Add();
}).Render();
<script type="text/x-jsrender" id="actionColumnTemplateDetail">
<div>
<button type="button" class="btn btn-primary btnOpenDetail" data-toggle="tooltip" data-placement="right"
onclick="openDetailDialog(this);"
title="@Resource.ExpenseTypeViewModel_BtnDetailsTitle">
<span class="fa fa-search-plus" style="margin-left: auto;"></span>
</button>
</div>
</script>
//Controller
public void ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
var GridModel = string.Empty;
var DataSource = new ExpenseTypesListViewModel().ExpenseTypes.ToList();
GridProperties obj = ConvertGridObject(GridModel);
exp.Export(obj, DataSource, "Export.xlsx", ExcelVersion.Excel2010, false, false, "flat-saffron"); the line where the error occurs
return View();
}
private GridProperties ConvertGridObject(string gridProperty)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
IEnumerable div = (IEnumerable)serializer.Deserialize(gridProperty.ToString(), typeof(IEnumerable));
GridProperties gridProp = new GridProperties();
foreach (KeyValuePair<string, object> ds in div)
{
var property = gridProp.GetType().GetProperty(ds.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);
if (property != null)
{
Type type = property.PropertyType;
string serialize = serializer.Serialize(ds.Value);
object value = serializer.Deserialize(serialize, type);
property.SetValue(gridProp, value, null);
}
}
return gridProp;
}