This question is locked. New answers and comments are not allowed.
I am attempting to use the Grid Export feature, and get a 500 error each time the Ajax call returns from the controller. I have struggled with this issue for 16 hours and finally have decided to get help. I downloaded the Northwind export example and it works fine. However, in my code I keep getting a 500 error popup. Here is my code:
[controller]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClientView.DAL;
using ClientView.Models;
using ClientView.ViewModels;
using Telerik.Web.Mvc;
using System.Collections;
using System.IO;
using System.Text;
namespace ClientView.Controllers
{
[Authorize]
public class HomeController : Controller
{
private ClientViewContext db = new ClientViewContext();
public ActionResult Index()
{
return View(Model());
}
private IQueryable<ClientClaim> Model()
{
IQueryable <ClientClaim> ClientClaims =
(from a in db.CLAIMs
orderby a.DATE descending
where a.ClientID == "20758" && a.SUBNUMBER == "0"
select new ClientClaim
{
ID = a.ID,
INVOLVED = a.INVOLVEDs.Where(i => i.ROLE == "INSURED1").FirstOrDefault(),
Examiner = a.ATTENTION,
LossDate = a.DATE,
STGCLAIM = a.STGCLAIMs.Where(i => i.END == null).FirstOrDefault(),
ClientClaimNum = a.CLAIMNUM,
Policy = a.POLICYNO,
Status = a.STATUS,
ADJUSTER = a.ADJUSTER
});
return ClientClaims;
}
[HttpPost]
[GridAction]
public ActionResult _Index()
{
var model = Model();
return View(new GridModel { Data = model });
}
public ActionResult About()
{
return View();
}
public ActionResult ExportCsv(int page, string orderBy, string filter)
{
// will trap here to check parameters
return View();
}
}
}
[View]
@{
ViewBag.Title = "Client Claims";
}
@model IEnumerable<ClientView.ViewModels.ClientClaim>
@(Html.Telerik().Grid(Model)
.Name("Grid")
.ToolBar(commands => commands
.Custom()
.HtmlAttributes(new { id = "exportLink" })
.Text("Export to CSV")
.Action("ExportCsv", "Home", new { page = 1, orderBy = "~", filter = "~" }
))
.DataKeys(dataKeys => dataKeys.Add(a => a.ID))
.Columns(columns =>
{
columns.Command(commands => commands.Select()).Title("Details");
columns.Bound(c => c.ClientClaimNum).Title("Claim Number");
columns.Bound(c => c.Policy).Title("Policy");
columns.Bound(c => c.INVOLVED.Name).Title("Insured");
columns.Bound(c => c.Examiner).Title("Examiner");
columns.Bound(c => c.ADJUSTER.Name).Title("Adjuster");
columns.Bound(c => c.LossDate).Title("Loss Date").Format("{0:MM/dd/yyyy}");
columns.Bound(c => c.STGCLAIM.Name).Title("Stage");
columns.Bound(c => c.Status).Title("Status");
})
.Pageable()
.Sortable()
.Filterable()
.DataBinding(dataBinding => dataBinding.Ajax().Select("_Index", "Home"))
.ClientEvents(events => events.OnDataBound("onDataBound"))
)
<script type="text/javascript">
function onDataBound() {
var grid = $(this).data('tGrid');
var $exportLink = $('#exportLink');
var href = $exportLink.attr('href');
href = href.replace(/page=([^&]*)/, 'page=' + grid.currentPage);
href = href.replace(/orderBy=([^&]*)/, 'orderBy=' + (grid.orderBy || '~'));
href = href.replace(/filter=(.*)/, 'filter=' + (grid.filterBy || '~'));
$exportLink.attr('href', href);
}
</script>
For the life of me, I can't figure this out. I'm sure sure it is obvious to somebody more experienced than me. Needless to say, I would really appreciate a solution to this.
TIA Gene
[controller]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ClientView.DAL;
using ClientView.Models;
using ClientView.ViewModels;
using Telerik.Web.Mvc;
using System.Collections;
using System.IO;
using System.Text;
namespace ClientView.Controllers
{
[Authorize]
public class HomeController : Controller
{
private ClientViewContext db = new ClientViewContext();
public ActionResult Index()
{
return View(Model());
}
private IQueryable<ClientClaim> Model()
{
IQueryable <ClientClaim> ClientClaims =
(from a in db.CLAIMs
orderby a.DATE descending
where a.ClientID == "20758" && a.SUBNUMBER == "0"
select new ClientClaim
{
ID = a.ID,
INVOLVED = a.INVOLVEDs.Where(i => i.ROLE == "INSURED1").FirstOrDefault(),
Examiner = a.ATTENTION,
LossDate = a.DATE,
STGCLAIM = a.STGCLAIMs.Where(i => i.END == null).FirstOrDefault(),
ClientClaimNum = a.CLAIMNUM,
Policy = a.POLICYNO,
Status = a.STATUS,
ADJUSTER = a.ADJUSTER
});
return ClientClaims;
}
[HttpPost]
[GridAction]
public ActionResult _Index()
{
var model = Model();
return View(new GridModel { Data = model });
}
public ActionResult About()
{
return View();
}
public ActionResult ExportCsv(int page, string orderBy, string filter)
{
// will trap here to check parameters
return View();
}
}
}
[View]
@{
ViewBag.Title = "Client Claims";
}
@model IEnumerable<ClientView.ViewModels.ClientClaim>
@(Html.Telerik().Grid(Model)
.Name("Grid")
.ToolBar(commands => commands
.Custom()
.HtmlAttributes(new { id = "exportLink" })
.Text("Export to CSV")
.Action("ExportCsv", "Home", new { page = 1, orderBy = "~", filter = "~" }
))
.DataKeys(dataKeys => dataKeys.Add(a => a.ID))
.Columns(columns =>
{
columns.Command(commands => commands.Select()).Title("Details");
columns.Bound(c => c.ClientClaimNum).Title("Claim Number");
columns.Bound(c => c.Policy).Title("Policy");
columns.Bound(c => c.INVOLVED.Name).Title("Insured");
columns.Bound(c => c.Examiner).Title("Examiner");
columns.Bound(c => c.ADJUSTER.Name).Title("Adjuster");
columns.Bound(c => c.LossDate).Title("Loss Date").Format("{0:MM/dd/yyyy}");
columns.Bound(c => c.STGCLAIM.Name).Title("Stage");
columns.Bound(c => c.Status).Title("Status");
})
.Pageable()
.Sortable()
.Filterable()
.DataBinding(dataBinding => dataBinding.Ajax().Select("_Index", "Home"))
.ClientEvents(events => events.OnDataBound("onDataBound"))
)
<script type="text/javascript">
function onDataBound() {
var grid = $(this).data('tGrid');
var $exportLink = $('#exportLink');
var href = $exportLink.attr('href');
href = href.replace(/page=([^&]*)/, 'page=' + grid.currentPage);
href = href.replace(/orderBy=([^&]*)/, 'orderBy=' + (grid.orderBy || '~'));
href = href.replace(/filter=(.*)/, 'filter=' + (grid.filterBy || '~'));
$exportLink.attr('href', href);
}
</script>
For the life of me, I can't figure this out. I'm sure sure it is obvious to somebody more experienced than me. Needless to say, I would really appreciate a solution to this.
TIA Gene