Reputation: 101192
I want to be able to get the result that the ActionResult
will generate directly in my controller for debugging purposes. How do I do that?
Something like:
public ActionResult Parts(string id)
{
var parts = _repository.GetParts(id);
var action = Json(parts);
var generatedJson = XXXXX;
return action;
}
Upvotes: 2
Views: 1269
Reputation: 1039508
For debugging purposes you definitely want to use a debugging tool such as FireBug or Fiddler, but if you insist pollutingmodifying your source code when in Debug mode you could take a look at the JavaScriptSerializer class (which is internally used by the JsonResult class):
var generatedJson = new JavaScriptSerializer().Serialize(parts);
Upvotes: 2
Reputation: 22485
you could also use something like NLog and bind it to ILogger in your global.asax. thereafter, you can temporarily send any json related controller actions out to the log file for later inspection.
another way is to use an actionfilter and decorate the action that you wanna capture (these could be saved in a log file or some other visual rendering device). there's a good example of this that you could adapt for your purposes here:
http://binary-studio.com/blog/technical-blog/asp-net-mvc-custom-action-filters/
hope this helps..
Upvotes: 0
Reputation: 6029
Call ExecuteResult on the result.
But if you want to inspect the json returned by it, use the browser debugging tools along with some json viewer add-on.
Upvotes: 0