views:

187

answers:

1

Is it possible to Multiple Objects Using ASP.NET MVC'S JsonResult Class.... Here is a controller method which returns json object of my records but i also want to pass the count value....

var materials = consRepository.FindAllMaterials().AsQueryable();
var count = materials.Count();
var results = new PagedList<MaterialsObj>(materials, currentPage-1, pageSize);
return Json(results);

How to return count along with the results from asp.net mvc controller....

+2  A: 

How about creating an anonymous type and JSON'ing that?

e.g.

var resultCount = results.Count;
var genericResult = new { Count = resultCount, Results = results };
return Json(genericResult);

You can then eval your json string in your script as before but just query the Count and Results properties on your eval result.

Neil Moss
My assumption was you were calling the eval function yourself. If you've done a jQuery call specifying a json result type, it will already have done that.
Neil Moss
@Neil i just used `data.Count` it gave me the result...
Pandiya Chendur