This question is locked. New answers and comments are not allowed.
I am using MVC3 with Razor view engine and the Grid control.
I am using Entity Framework as a datasource and I have tried to replicate a simple Ajax bound grid with paging following the examples to no avail. I get the following error message:
The model item passed into the dictionary is of type 'Telerik.Web.Mvc.GridModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[TelerikMvcApplication2.PROCESS_OBJECT]'.
This is my Controller:
using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using TelerikMvcApplication2; using Telerik.Web.Mvc; using Telerik.Web.Mvc.UI; namespace TelerikMvcApplication2.Controllers { public class JobController : Controller { private BODS_ETL_CONTROLEntities db = new BODS_ETL_CONTROLEntities(); // // GET: /Job/ public ActionResult Paging(bool? pageInput, bool? nextPrevious, bool? numeric, GridPagerPosition? position, int? currentPage, bool? pageSize) { ViewData["pageInput"] = pageInput ?? false; ViewData["nextPrevious"] = nextPrevious ?? true; ViewData["numeric"] = numeric ?? true; ViewData["pageSize"] = pageSize ?? false; ViewData["position"] = position ?? GridPagerPosition.Bottom; ViewData["currentPage"] = currentPage ?? 1; var process_object = db.PROCESS_OBJECT.Include("PROCESS_OBJECT_TYPE"); return View(new GridModel(process_object.ToList())); } [GridAction] public ActionResult _Paging() { var process_object = db.PROCESS_OBJECT.Include("PROCESS_OBJECT_TYPE"); //return View(new GridModel(process_object.ToList())); return View(new GridModel<TelerikMvcApplication2.PROCESS_OBJECT> { Data = process_object }); } [GridAction] public ActionResult _AjaxBinding() { var process_object = db.PROCESS_OBJECT.Include("PROCESS_OBJECT_TYPE"); return View(new GridModel(process_object.ToList())); } public ViewResult Index() { ViewData["pageInput"] = false; ViewData["nextPrevious"] = true; ViewData["numeric"] = true; ViewData["pageSize"] = false; ViewData["position"] = GridPagerPosition.Bottom; ViewData["currentPage"] = 1; var process_object = db.PROCESS_OBJECT.Include("PROCESS_OBJECT_TYPE"); return View(process_object.ToList()); } // // GET: /Job/Details/5 public ViewResult Details(int id) { PROCESS_OBJECT process_object = db.PROCESS_OBJECT.Single(p => p.OBJECT_ID == id); return View(process_object); } // // GET: /Job/Create public ActionResult Create() { ViewBag.OBJECT_TYPE_ID = new SelectList(db.PROCESS_OBJECT_TYPE, "OBJECT_TYPE_ID", "OBJECT_TYPE_NAME"); return View(); } // // POST: /Job/Create [HttpPost] public ActionResult Create(PROCESS_OBJECT process_object) { if (ModelState.IsValid) { db.PROCESS_OBJECT.AddObject(process_object); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.OBJECT_TYPE_ID = new SelectList(db.PROCESS_OBJECT_TYPE, "OBJECT_TYPE_ID", "OBJECT_TYPE_NAME", process_object.OBJECT_TYPE_ID); return View(process_object); } // // GET: /Job/Edit/5 public ActionResult Edit(int id) { PROCESS_OBJECT process_object = db.PROCESS_OBJECT.Single(p => p.OBJECT_ID == id); ViewBag.OBJECT_TYPE_ID = new SelectList(db.PROCESS_OBJECT_TYPE, "OBJECT_TYPE_ID", "OBJECT_TYPE_NAME", process_object.OBJECT_TYPE_ID); return View(process_object); } // // POST: /Job/Edit/5 [HttpPost] public ActionResult Edit(PROCESS_OBJECT process_object) { if (ModelState.IsValid) { db.PROCESS_OBJECT.Attach(process_object); db.ObjectStateManager.ChangeObjectState(process_object, EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.OBJECT_TYPE_ID = new SelectList(db.PROCESS_OBJECT_TYPE, "OBJECT_TYPE_ID", "OBJECT_TYPE_NAME", process_object.OBJECT_TYPE_ID); return View(process_object); } // // GET: /Job/Delete/5 public ActionResult Delete(int id) { PROCESS_OBJECT process_object = db.PROCESS_OBJECT.Single(p => p.OBJECT_ID == id); return View(process_object); } // // POST: /Job/Delete/5 [HttpPost, ActionName("Delete")] public ActionResult DeleteConfirmed(int id) { PROCESS_OBJECT process_object = db.PROCESS_OBJECT.Single(p => p.OBJECT_ID == id); db.PROCESS_OBJECT.DeleteObject(process_object); db.SaveChanges(); return RedirectToAction("Index"); } protected override void Dispose(bool disposing) { db.Dispose(); base.Dispose(disposing); } } }This is my view for Paging Action:
<!-- model IEnumerable<TelerikMvcApplication2.PROCESS_OBJECT> --> @model IEnumerable<TelerikMvcApplication2.PROCESS_OBJECT> @{ ViewBag.Title = "Paging"; } <h2>Paging</h2> <p> @Html.ActionLink("Create New", "Create") </p> @{ var pagerStyleFlags = new[] { new { Key = "pageInput", Value = GridPagerStyles.PageInput }, new { Key = "nextPrevious", Value = GridPagerStyles.NextPrevious }, new { Key = "numeric", Value = GridPagerStyles.Numeric }, new { Key = "pageSize", Value = GridPagerStyles.PageSizeDropDown } }; GridPagerStyles pagerStyles = GridPagerStyles.NextPreviousAndNumeric; foreach (var pagerStyleFlag in pagerStyleFlags) { bool pagerStyle = (bool)ViewData[pagerStyleFlag.Key]; if (pagerStyle == true) { pagerStyles |= pagerStyleFlag.Value; } else { pagerStyles &= ~pagerStyleFlag.Value; } } var position = (GridPagerPosition)ViewData["position"]; var currentPage = (int)ViewData["currentPage"]; currentPage = Math.Max(currentPage, 1); currentPage = Math.Min(currentPage, 83); } @{Html.Telerik().Grid(Model) .Name("Job") .DataBinding(dataBinding => dataBinding.Ajax().Select( "_Paging","Job")) .Pageable(paging => paging.Style(pagerStyles).Position(position).PageTo(currentPage)) .Sortable().Render(); }I have seen others with a similar issue but I can not spot the difference. Any help would be greatly appreciated :-)
Thanks,
Carey