Hi,
I'm using MVC 6 in my project and i'm trying to export grid content using excel option. While debugging, the controller method is hit but nothing happens after the last line.
Kindly help.
Code:
public async Task ExportToExcel(string GridModel)
{
//Declarations
var exp = new ExcelExport();
//Get User Detail
var user = await GetCurrentUserAsync();
//Get Grid Datasource
var dataSource = _repo.GetUserList(user.TeamId);
//Convert to Grid Object
var obj = ConvertGridObject(GridModel);
//Set Properties
var properties = new GridExcelExport
{
FileName = "Export.xlsx",
Excelversion = ExcelVersion.Excel2010,
Theme = "flat-saffron",
LocalSave = true
};
//Export Grid
exp.Export(obj, dataSource, properties);
}
private static GridProperties ConvertGridObject(string gridProperty)
{
var serializer = new JavaScriptSerializer();
var div = (IEnumerable)serializer.Deserialize(gridProperty, typeof(IEnumerable));
var 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)
{
var type = property.PropertyType;
var serialize = serializer.Serialize(ds.Value);
var value = serializer.Deserialize(serialize, type);
property.SetValue(gridProp, value, null);
}
}
return gridProp;
}
Thanks.