Working with JSON

The examples so far in this chapter have worked on fragments of HTML, but the MVC framework makes it very easy to work with JSON data as well. Listing 30-13 shows how we create an action method that produces JSON data.

Listing 30-13. Creating an action method that produces JSON

using System.Linq; using System.Web.Mvc; using EventRegistration.Models.Domain.Repository; namespace EventRegistration.Controllers {     public class ReportsController : Controller {         private IRepository repository;         public ReportsController(IRepository repo) {             repository = repo;         }         public ActionResult Index(string competition) {             ViewBag.CompetitionNames = repository.Competitions.Select(x => x.Name); ...

Get Applied ASP.NET 4 in Context now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.