I have a simple web service I wrote using Webmatrix that returns data in json. I liked to consume that service using ASP.NET MVC 3. I know how to do this with WCF but we are not going to use WCF on this project. Is there something akin to jquery’s getJson() method in ASP.NET MVC where I just pass in the restful url and it returns the data and I handle it in a callback? Thanks for any help 🙂
Here’s my service:
URL:
/services/GetAllItemsService
Code:
@{
var items = ItemsService.GetAllItems();
Json.Write(items, Response.Output);
}
You could use a WebClient to fetch the JSON data from a remote resource. For example:
Or if you wanted to write the JSON directly to the output: