This is a migrated thread and some comments may be shown as answers.

[Solved] Telerik Grid Export Ajax call generating 500 error

5 Answers 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gene
Top achievements
Rank 1
Gene asked on 22 Mar 2012, 09:14 PM
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

5 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 23 Mar 2012, 09:20 AM
Hi,

 Error 500 means that there is a server side exception. You can check the output using Fiddler or other HTTP sniffing tool. That output will contain the stacktrace. You can then check the troubleshooting help article.

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Gene
Top achievements
Rank 1
answered on 23 Mar 2012, 01:57 PM
I used fiddler to identify the source of the error. It identified a circular reference. After removing the reference, I can see the Grid Model object is being returned as a response, not html. I guess what is confusing, is that in the ExcelExport example, the ajax call is made to "IndexAjax", but there is no view.cshtml file associated. How is the html rendered?

Further examination shows what appears to be a json response returned. The only observable behaviour on the client side is animation of the refresh icon in the lower left corner. It spins indefinitely and there are no other observable differences on the screen. That is, clicking on a column to sort, does not sort the data, but the refresh icon spins.
0
Atanas Korchev
Telerik team
answered on 23 Mar 2012, 02:35 PM
Hello,

 The export example outputs the generated file in the response. No view is needed in this case.

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Gene
Top achievements
Rank 1
answered on 23 Mar 2012, 02:37 PM
I gathered that from the json response. However, now it appears to be "hung" on the client side. Any suggestions as to how I might determine where this is happening?
0
Gene
Top achievements
Rank 1
answered on 23 Mar 2012, 03:08 PM
I believe I have found the issue. Apparently there is something a little too complicated about the returned json response. By simplifying my query and eliminating the "Virtual" collections, I got it to work. Thank you for your assistance!
Tags
Grid
Asked by
Gene
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gene
Top achievements
Rank 1
Share this question
or