2

I have an object which I return wrapped in Json from the controller to the client.

return Json(result); //result is DataSourceResult

I would like to add some more properties inside this Json response.

How can I do so?

I tried using Json property Data and also casting the DataSourceResult to object and trying to expand it, but whatever I have doesn't look like a good solution.

Anelook
  • 1,277
  • 3
  • 17
  • 28
  • 1
    Show controller action code & what properties you want to add. You can return anonymous object – Satpal Dec 02 '13 at 09:40
  • `return Json(new{result=result, someprop="1234"});` ??? – L.B Dec 02 '13 at 09:41
  • Oh, stupid me, I was looking how to expand the result object, when there was a much easier and better solution. Monday morning is usually a tough time to think :D – Anelook Dec 03 '13 at 08:57

1 Answers1

2

You can return anonymous object like

return Json(new {
    result = result,
    myProperty1 = value1,
    myProperty2 = value2
});
Satpal
  • 132,252
  • 13
  • 159
  • 168