i have a telerik mvc grid where the excel export function fails because the read action of the grid has extra parameters. the read action looks like this :
public ActionResult My_ReadAction([DataSourceRequest]DataSourceRequest request, string startDate, string endDate)
{
DateTime _startDate, _endDate;
_startDate = DateTime.ParseExact(startDate, "yyyyMMdd", CultureInfo.InvariantCulture);
_endDate = DateTime.ParseExact(endDate, "yyyyMMdd", CultureInfo.InvariantCulture);
IQueryable<CM_DISTRIBUTION_SCHEDULE> cm_distribution_schedule = db.CM_DISTRIBUTION_SCHEDULE
.Where(x => x.REF_DATE >= _startDate && x.REF_DATE <= _endDate);
DataSourceResult result = cm_distribution_schedule.ToDataSourceResult(request, cM_DISTRIBUTION_SCHEDULE => new
{
RECORD_ID = cM_DISTRIBUTION_SCHEDULE.RECORD_ID,
REF_DATE = cM_DISTRIBUTION_SCHEDULE.REF_DATE,
BRANCH_ID = cM_DISTRIBUTION_SCHEDULE.BRANCH_ID,
CURRENCY = cM_DISTRIBUTION_SCHEDULE.CURRENCY,
FORECAST_AMOUNT = cM_DISTRIBUTION_SCHEDULE.FORECAST_AMOUNT
});
return Json(result);
}
and the grid :
@(Html.Kendo().Grid<MyClass.MyViewModel>().Name("BranchFcast").AutoBind(false) .HtmlAttributes(new { style = "height: 100%; border: 0;" })
.Columns(columns =>
{
columns.Bound(c => c.REF_DATE).Title("Forecast Date").Format("{0:d}").Width(130);
columns.ForeignKey(f => f.BRANCH_ID, (System.Collections.IEnumerable)ViewData["branches"], "BranchId", "BranchName").Title("Branch").Width(200);
columns.ForeignKey(f => f.CURRENCY, (System.Collections.IEnumerable)ViewData["currencies"], "CurrencyId", "CurrencyName").Title("Currency").Width(150);
columns.Bound(c => c.FORECAST_AMOUNT).Title("Forecast Amount").Format("{0:c}").Width(150);
columns.Bound(c => c.TXN_AMOUNT).Title("Amended Forecast").Width(150);
})
.ToolBar(toolbar => {
toolbar.Excel();
}).Excel(excel => excel.FileName("DistSchedule.xlsx").Filterable(true).ProxyURL(Url.Action("Excel_Export_Save", "DistSched")).AllPages(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Model(model =>
{
model.Id(p => p.RECORD_ID);
model.Field(p => p.RECORD_ID).Editable(false);
model.Field(p=> p.REF_DATE).DefaultValue(DateTime.Today);
}
)
.Sort(s => s.Add(f => f.REF_DATE).Descending()).Read(read => read.Action("My_ReadAction", "Controller")))
)
So when the export button is clicked, it fires My_ReadAction but doesnt pass the parameter, causing the controller action to fail. Is there a way to modify the export events such that i can pass the parameters. Any other workaround is welcome.
Add a .Data()
fluent method to the Ajax DataSource settngs and implement a JavaScript function that will return a plain object with the two dates. This is the recommended way to pass custom parameters to the Grid's Read action method.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.