Yasser Shaikh
Yasser Shaikh

Reputation: 47784

Is it recommended to return json data from a web api method in ASP.NET MVC 4?

Is it recommended to return json data from a web api method ?

This I am using for jqgrid.

I am using WebApi for all other operations like Get, Update, Delete etc...

Thanks

Upvotes: 1

Views: 255

Answers (1)

Wouter de Kort
Wouter de Kort

Reputation: 39898

WebApi supports Content Negotation. This means that it will give you what you ask for. WebApi will inspect the header of your request and will then return the data in the correct format.

In case of an AJAX application using jqGrid, you will probably ask for JSON. That's the easiest format to use in JavaScript.

If someone else would call your WebApi method and ask for Xml, your method would return Xml to the caller.

Upvotes: 3

Related Questions