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

[Solved] Need To Be Able To Send Custom Data With AJAX Requests

2 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.
Kevin Watkins
Top achievements
Rank 1
Kevin Watkins asked on 13 Jan 2010, 05:37 PM
Hi,

I could do with being able to send custom data along with AJAX requests. This is when I have custom filtering (i.e. not the filtering built into the grid) defined using custom controls in the page. I need to send the details of this filter along with the AJAX requests so that my AJAX GridAction methods know what filter parameters to use when fetching the data. And sadly the stuff I need to too complex to encode in the route values in the AJAX method...

I have managed to add custom functionality to the Telerik.Web.Mvc assembly to do all this. The Ajax declaration in my view code now looks something like:

.Ajax(ajax => ajax.Action("MyGrid""MyController").CustomFilter(Model.Filter)) 

And my AJAX grid method signature looks like:

[GridAction(EnableCustomBinding = true, CustomFilterType = typeof(MyFilter))]  
public ViewResult MyGrid(MyFilter filter, GridCommand command) 

It throws the filter object around as JSON in the background. Happy to send over the code if you want.

Wondering if you planned to add anything like this in the future? I'd prefer to use the official way to do things if possible!

Thanks,

Kev

2 Answers, 1 is accepted

Sort by
0
James Davies
Top achievements
Rank 1
answered on 13 Jan 2010, 08:56 PM
Hi Kevin,

I think what you want is built in?  See for example:

    http://demos.telerik.com/aspnet-mvc/grid/relatedgrids

    Regards,
    Jim
0
Kevin Watkins
Top achievements
Rank 1
answered on 13 Jan 2010, 09:25 PM
Nope, that example uses route values to encode the data, i.e. the data is made part of the URL. The filter I have is too complex to (easily) encode in route values. For example I have a collection of IDs so I'd have to write routines to convert that list into a string which I could then use as a route value. I don't want to have to keep writing custom conversion code like that so I've added extra code to the grid that encodes an arbitrary object as JSON and sends it to the client. (I've done it as JSON so you could access the data client side if desired) This then gets included in the POST data of the grid requests and I deserialize server side.

Kev
Tags
Grid
Asked by
Kevin Watkins
Top achievements
Rank 1
Answers by
James Davies
Top achievements
Rank 1
Kevin Watkins
Top achievements
Rank 1
Share this question
or