Represents a class that is used to send JSON-formatted content to the response.
Questions tagged [jsonresult]
273 questions
537
votes
37 answers
Fastest way to check if a string is JSON in PHP?
I need a really, really fast method of checking if a string is JSON or not. I feel like this is not the best way:
function isJson($string) {
return ((is_string($string) &&
(is_object(json_decode($string)) ||
…

Kirk Ouimet
- 27,280
- 43
- 127
- 177
139
votes
15 answers
MaxJsonLength exception in ASP.NET MVC during JavaScriptSerializer
In one of my controller actions I am returning a very large JsonResult to fill a grid.
I am getting the following InvalidOperationException exception:
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of…

Martin Buberl
- 45,844
- 25
- 100
- 144
103
votes
7 answers
Using JSON.NET as the default JSON serializer in ASP.NET MVC 3 - is it possible?
Is it possible to use JSON.NET as default JSON serializer in ASP.NET MVC 3?
According to my research, it seems that the only way to accomplish this is to extend ActionResult as JsonResult in MVC3 is not virtual...
I hoped that with ASP.NET MVC 3…

zam6ak
- 7,229
- 11
- 46
- 84
68
votes
1 answer
Can I convert a JSON string into JsonResult?
I have some stored JSON strings stored in the DB which I want to return to the client as JsonResult . I know that Json(object) turns an object into JsonResult but what if I already have the result in a string ? can I cast it to JsonResult

xantrus
- 1,975
- 1
- 22
- 44
49
votes
9 answers
How to unit test an Action method which returns JsonResult?
If I have a controller like this:
[HttpPost]
public JsonResult FindStuff(string query)
{
var results = _repo.GetStuff(query);
var jsonResult = results.Select(x => new
{
id = x.Id,
name = x.Foo,
type = x.Bar
…

RPM1984
- 72,246
- 58
- 225
- 350
39
votes
5 answers
Actionresult vs JSONresult
I have 2 questions:
What is the difference between JSONResult and ActionResult?
When to use JSONResult in MVC?

Sameer More
- 589
- 1
- 6
- 13
28
votes
1 answer
JsonResult return Json in ASP.NET CORE 2.1
Controller that worked in ASP.NET Core 2.0:
[Produces("application/json")]
[Route("api/[controller]")]
[ApiController]
public class GraficResourcesApiController : ControllerBase
{
private readonly ApplicationDbContext _context;
public…

blakcat
- 634
- 1
- 7
- 16
25
votes
5 answers
How to redirect to a controller action from a JSONResult method in ASP.NET MVC?
I am fetching records for a user based on his UserId as a JsonResult...
public JsonResult GetClients(int currentPage, int pageSize)
{
if (Session["UserId"] != "")
{
var clients = clirep.FindAllClients().AsQueryable();
var count =…

ACP
- 34,682
- 100
- 231
- 371
15
votes
2 answers
JsonResult or Json: which to use?
In ASP.NET MVC 3, which is more correct to use: Json() or new JsonResult()? Either returns the same result. Thanks for helping solve an office debate.

Darth Coder
- 153
- 1
- 5
15
votes
5 answers
Returning JSON from a JsonResult method in MVC controller
I am trying to populate a ComboBox (Telerik RAD COmboBox) in a test ASP.NET MVC3 app.
I have defined the ComboBox on my ASPX page and in the controller I have defined the action call that returns a JsonResult.
The problem I am having is that the Web…

MAB
- 153
- 1
- 1
- 5
14
votes
1 answer
ASP.NET MVC - Pass Json String to View using ViewData
I'm trying to pass Json to my View using ViewData
Controller
ViewData("JsonRegionList") = Json(RegionService.GetActiveRegions())
view
$("input#UserRegion").autocomplete({
source:"<%: ViewData("JsonRegionList").ToString %>",
…

Chase Florell
- 46,378
- 57
- 186
- 376
12
votes
1 answer
How should I return 404 from a JsonResult Controller?
In ASP.NET MVC5 I have a controller with a JsonResult return type.
Depending on parameters I want to return a 404, as this is descriptive of the user requesting non-existent data.
I could throw new HttpException(404, "message") but this feels dirty…

Matthew
- 10,244
- 5
- 49
- 104
12
votes
2 answers
How to read a property of an anonymous type?
I have a method that returns
return new System.Web.Mvc.JsonResult()
{
Data = new
{
Status = "OK",
}
}
I need to write a unit test where I need to verify that jsonResult.Data.status= "OK".
How do I read…

developer747
- 15,419
- 26
- 93
- 147
11
votes
2 answers
Asp.net MVC - Jquery $.ajax error callback is not returning responseJSON
I have the code below, with works fine on the development machine but not when called from a remote browser...
$.ajax({
type: 'POST',
url: '@Url.Action("Action", "Controller")',
data: { id: id },
dataType: 'json',
async: true,
success:…

Junior Silva
- 387
- 5
- 17
11
votes
6 answers
Cannot implicitly convert Web.Http.Results.JsonResult to Web.Mvc.JsonResult
I've set up this test method on a controller to strip out any complication to it. Based off of all the results I've found from searching this should work. I'm not sure what I'm missing here.
public JsonResult test()
{
return Json(new { id = 1…

Jhorra
- 6,233
- 21
- 69
- 123