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

[Solved] Fields being removed from Json response

3 Answers 116 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.
Herbert
Top achievements
Rank 1
Herbert asked on 13 Jul 2012, 02:19 PM
Hello,

I currently have a grid with a controller action set on the Update Ajax databinding.

The following is a code snippet of the controller action:

[GridAction(EnableCustomBinding = true)]
public ActionResult UpdateData(GridCommand command)
{
     //logic here
     return Json(new { Data = data, Total = total, Errors = errors });
}


"errors" is a string array that we populate. The errors are later parsed to show up in our view.
However I've noticed that when the GridAction tag is set, only Data and Total are returned in the response. I'm aware that due to using GridAction, the OnActionExecuted will ignore all but a few fields such as Data and Total. Is there a solution to this that preferably does not modify Telerik source code?

Thanks

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 Jul 2012, 06:54 AM
Hello Herbert,

You could add the error messages as model state errors and they will be automatically serialized 
by the GridAction attribute and added to the response.

[GridAction(EnableCustomBinding = true)]
public ActionResult UpdateData(GridCommand command)
{
     .....
     ModelState.AddModelError("myErrorKey", "my error message");
     return Json(new { Data = data, Total = total});
}
Kind regards,
Daniel
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 15 Aug 2012, 01:53 PM
Hello,

The provided solution seems not to work. Even if I add error to the model state, response still doesn't have the error message in the provided scenario, and it only has data and total.
0
Daniel
Telerik team
answered on 17 Aug 2012, 01:32 PM
Hello,

Sorry, indeed there is an problem with the provided snippet. A ViewResult with the GridModel should be returned from the action so that the GridActionAttribute can access the errors e.g.

[GridAction(EnableCustomBinding = true)]
public ActionResult UpdateData(GridCommand command)
{
     .....
     ModelState.AddModelError("myErrorKey", "my error message");
     return View(new GridModel{ Data = data, Total = total});
}
Regards,
Daniel
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.
Tags
Grid
Asked by
Herbert
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Kuangyi
Top achievements
Rank 1
Share this question
or