I found the MVC API Action filter which should automatically check if the request demands a json response and if so automatically serialize in json the model i was sending to the view, right ?!
I found many examples but the thing is they all assume that the request will be sent by an Ajax call in which i can clearly specify it’s a json request.
I want to call the action directly from my browser but i’m not without any specification it simply returns the view
How do i specify in the url that i’m requesting a json response?
I know of the library that you write of, but haven’t used it. I shied away from using it when I saw that it never seems to have made it out of Beta on Codeplex and hasn’t been updated in over a year.
That aside, in the methodology being used, the URL doesn’t determine the data type coming back, the Http Accept Headers are what does it. This is a more RESTful approach to returning data.
You’ll note on the link that you provided in the Request section that
application/jsonis what tells the service to return json. You may find other examples on the web that saytext/jsoninstead, and they should work also, butapplication/jsonis the correct standard.If you’re using jQuery, you can use
$.ajaxand specifydataType: 'json'or just use the$.getJsonmethod directly.