Guest User

KO MVC Sample - Controller

a guest
Feb 11th, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Web.Mvc;
  3. using WebApplication1.Models;
  4.  
  5. namespace KOSample.Controllers
  6. {
  7.     public class HomeController : Controller
  8.     {
  9.         public ActionResult Index()
  10.         {
  11.             return View();
  12.         }
  13.  
  14.         [HttpPost]
  15.         public JsonResult PostDriversModel(DriversModel model)
  16.         {
  17.             return Json(new { Success = true }, JsonRequestBehavior.AllowGet);
  18.         }
  19.  
  20.         [HttpGet]
  21.         public JsonResult GetDriversModel()
  22.         {
  23.             var model = new DriversModel
  24.             {
  25.                 Drivers = new List<Driver>
  26.                 {
  27.                     new Driver
  28.                     {
  29.                         Cars = new List<Car>
  30.                         {
  31.                             new Car {Code = "car0", Name = "Amazing car"},
  32.                             new Car {Code = "car1", Name = "Cool car"}
  33.                         },
  34.                         FullName = "John Doe"
  35.                     },
  36.                     new Driver
  37.                     {
  38.                         Cars = new List<Car>
  39.                         {
  40.                             new Car {Code = "car2", Name = "Another Amazing car"},
  41.                             new Car {Code = "car3", Name = "Another Cool car"}
  42.                         },
  43.                         FullName = "Johnny Dough"
  44.                     },
  45.                 }
  46.             };
  47.  
  48.             return Json(model, JsonRequestBehavior.AllowGet);
  49.         }
  50.     }
  51. }
Add Comment
Please, Sign In to add comment