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

Creating a view for GridModel -- Need help figuring this out

4 Answers 102 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.
Matthew
Top achievements
Rank 2
Matthew asked on 15 May 2012, 07:20 PM
Hello,

I am using the ASP.NET MVC Grid in an app that has been working pretty well. I have a slight problem. I am using a Juniper SSL VPN (DANA) and it is mangling my Grid posts, to (as far as I can tell), get passed to the application as HTTP GET's, or otherwise screwing up the ajax call.


I can create a view called _AjaxBinding.cshtml in my shared directory, and it will spit it back out (using firebug/fiddler to look at the response). I can also furthermore look at Request.Forms and see that my page, size, filter args are all going through.


So. It seems like all I have to do is correctly format the GridView to JSON, and everything will work. I am currently using something like:

@model Telerik.Web.Mvc.GridModel
@{Layout = null;}
@Html.Raw(Json.Encode(Model))



How can I use skip/take on Model.Data to properly shrink my output? Also, something doesn't quite jive.

I understand that this is a little out of the ordinary, but all signs point to this working, if I can get my JSON to look identical to what is spit out when you Return View(new GridModel(whatever))

Thanks!

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 May 2012, 02:39 PM
Hello Matthew,

I am not sure if I understand exactly the issue with the requests but in order to apply paging, sorting, filtering, etc to the data without the GridAction attribute, you can use the ToGridModel IQueryable extension method which is in the Telerik.Web.Mvc.Extensions namespace.

Kind regards,
Daniel
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
Matthew
Top achievements
Rank 2
answered on 21 May 2012, 08:19 PM
I've gotten this to (mostly) work by using the non-mini'd telerik.common.js and telerik.grid.js, and using the following as a view for _AjaxBinding 



@model Telerik.Web.Mvc.GridModel


            @{  int page = Convert.ToInt32(Request.Form["page"]); 
            int size = Convert.ToInt32(Request.Form["size"]);
            string orderBy = Request.Form["orderBy"];
            string filter = Request.Form["filter"];
            string groupBy = Request.Form["groupBy"];
Layout = null;
}
@Html.Raw(Json.Encode(Telerik.Web.Mvc.Extensions.QueryableExtensions.ToGridModel(Model.Data.AsQueryable(),page,size,orderBy,groupBy,filter)))

0
Matthew
Top achievements
Rank 2
answered on 21 May 2012, 08:47 PM
Further research reveals that standard telerik widget filtering provides the form post, but when I use e.g grid.filterby = "substringof(PartNumber,'cca')~and~substringof(Description,'')" and grid.pageTo(1), nothing happens.

This works fantastically on my non VPN deployment. I use grid.filterby (complex string here), and grid.pageto(1) for my filtering, as my users desire a simpler filter input than the default telerik implementation.

Something with the JS rewrite is mucking up the translation of filterBy into a form field
0
Matthew
Top achievements
Rank 2
answered on 21 May 2012, 09:00 PM
Fixed it, although why this line was getting rewritten is beyond me.

In Telerik.Grid.js line 761-763, the vpn was rewriting from:

          if(filter !== "") {
                    params[that.queryString.filter] = filter;                                        
                }

to:

   if(filter !== "") {
params[DanaGetFilter(that.queryString)] = filter;


Changing the line to:

   if(filter !== "") {
                    params["filter"] = filter;                                        
                }

Fixes most everything

Tags
Grid
Asked by
Matthew
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Matthew
Top achievements
Rank 2
Share this question
or