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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.