Tuesday, January 5, 2016

MVC Nested grid edit

using NestedGridMVC4.Models;
using NestedGridMVC4.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace NestedGridMVC4.Controllers
{
    public class RequestController : Controller
    {
        //
        // GET: /Request/

        public ActionResult List()
        {
            List<RequestVM> allRequest = new List<RequestVM>();

            // here MyDatabaseEntities is our data context
            using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                var o = dc.Requests.OrderByDescending(a => a.RequestId);
                foreach (var i in o)
                {
                    var od = dc.Tickets.Where(a => a.RequestId == i.RequestId).ToList();
                    allRequest.Add(new RequestVM { request = i, tickets = od });
                }
            }
            return View(allRequest);

        }

        public JsonResult UpdateTicket(Ticket ticket)
        {
            // Update model to your db 
            string message = "Success";
            return Json(message, JsonRequestBehavior.AllowGet); 
        }

    }
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.