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

[Solved] Getting Json object from ajaxrequest postback.

2 Answers 113 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.
Kuangyi
Top achievements
Rank 1
Kuangyi asked on 14 Aug 2012, 07:38 PM

When I call ajaxRequest on the grid - is there a way to get the json object which the server sends back. I add some extra parameters to it, in order not to go to the server twice. On

Databound event seems not to have it.

$('#Grid').data('tGrid').ajaxRequest(params);

*****server processes the request and sends json response back with some additional params

function onDataBound(){
//need to somehow get the additional params from the json object

}

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 17 Aug 2012, 01:46 PM
Hello Kuangyi,

Actually sending additional messages back to the client from the action method is not supported. 
I would like to suggest you to always display message that the operation has completed successfully and if there are errors you can declare them in the ModelState dictionary. This way they will be serialized and sent to the client where via the OnError event you can display them.

If you really need to send different messages each time there is an work-around which consists of overriding some the GridAction attribute methods.
To do so you should inherit the GridActionAttribute and override the OnActionExecuted and the CreateActionResult methods. The additional data can be obtained on the client from the event argument's response property of the OnComplete client-side event
e.g.

public class MyGridActionAttribute: GridActionAttribute
{
    private ActionExecutedContext context;
    //Add the ActionExecutedContext to the attribute in order to get access to the
    // Controller context
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        this.context = filterContext;
        base.OnActionExecuted(filterContext);
    }
   
    // Add the additional data from the ViewData/ViewBag to the result       
    protected override ActionResult CreateActionResult(object model)
    {
        var dictionary = model as Dictionary<string,object>;
        var data = context.Controller.ViewData["additionalData"];
        dictionary.Add("additionalData", data);
        return base.CreateActionResult(model);
    }
}

I have also attached a sample project which demonstrates this - once again I do not recommend this approach. Kind regards,
Petur Subev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Kuangyi
Top achievements
Rank 1
answered on 17 Aug 2012, 04:25 PM
Hi, I tried upgrading the DLL in my own project to the one in yours (so that I can get an updated version of the GridAction since my DLL is from 2011/03), however all my CSS is gone because it can't load the asset.axd.

What else do I need to do?  I replaced the css + js files, renamed the folder to 2012.1.214.340 and changed the DLL and XML to the new ones.


edit: It seems to be a 500 server error.

NVM I got it working.  I think it was because I forgot to rename a folder.
Tags
Grid
Asked by
Kuangyi
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Kuangyi
Top achievements
Rank 1
Share this question
or