Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hardcoded JsonpResult values

I have the following controller action:

[HttpGet]
        public JsonpResult  getTestValues(int? entityId, int? id)
        {
            return JsonpResult(WebResult.Success());
        }

I have a AJAX call that invokes this controller and has to parse the data object returned. How can I modify the above to return the following?

{"data":[{"T1":"[email protected]","T11":"1234-1234-1234-1234"},
{"T2":"[email protected]","T22":"1234-1234-1234-1234"}]}

I need this for testing the UI framework that I am working on. Any suggestions on how to return the above hardcoded data?

like image 765
dotNetNewbie Avatar asked Feb 24 '26 18:02

dotNetNewbie


1 Answers

Yes, you can do this using an anonymous type:

return JsonpResult {
    Data = new {
        data = new List<object> {
           new { T1 = "[email protected]", T11 = "1234-1234-1234-1234" },
           new { T2 = "[email protected]", T22 = "1234-1234-1234-1234" },
        }
    }
};
like image 176
alexn Avatar answered Feb 27 '26 08:02

alexn