Hello,
I am new to MVC and I am attempting to use the GRID to perform functions as I have in the past with the ASP.NET AJAX controls. I am using Entity Framework for my model and I have a controller in place. I have the grid in my view and I have it successfully pulling the data from the model to display but the Add, Edit, Delete functions are not firing properly. Whenever I hit any of those buttons it tries to go to the URL that I believe would be associated if I were not using the grid.
For example when I hit the edit button instead of opening the popup form it goes to: /Grid/Index/2?gvBeamlines-mode=edit which of course throws a 404 error. The add button goes here: /Grid?gvBeamlines-mode=insert and the delete button goes here: /Grid/Delete/2
The URL of the initial view with the grid is /Beamlines so why is it going to /Grid instead? None of the methods in the controller seem to be firing. I feel like I am missing some basic piece to make this work. My code looks very similar to the demo code so I'm not sure what is wrong. Any help would be appreciated. The view and controller code is below.
View:
Controller: (only some methods are in place so far)
I am new to MVC and I am attempting to use the GRID to perform functions as I have in the past with the ASP.NET AJAX controls. I am using Entity Framework for my model and I have a controller in place. I have the grid in my view and I have it successfully pulling the data from the model to display but the Add, Edit, Delete functions are not firing properly. Whenever I hit any of those buttons it tries to go to the URL that I believe would be associated if I were not using the grid.
For example when I hit the edit button instead of opening the popup form it goes to: /Grid/Index/2?gvBeamlines-mode=edit which of course throws a 404 error. The add button goes here: /Grid?gvBeamlines-mode=insert and the delete button goes here: /Grid/Delete/2
The URL of the initial view with the grid is /Beamlines so why is it going to /Grid instead? None of the methods in the controller seem to be firing. I feel like I am missing some basic piece to make this work. My code looks very similar to the demo code so I'm not sure what is wrong. Any help would be appreciated. The view and controller code is below.
View:
@model IEnumerable<MyLibrary.Beamline>@{ ViewBag.Title = "Beamlines";}<h2>Beamlines</h2>@(Html.Kendo().Grid(Model) .Name("gvBeamlines") .Columns(columns => { columns.Command(command => { command.Edit(); }).Width(50); columns.Bound(o => o.Description).Width(100); columns.Bound(o => o.Insertion_Device).Title("Insertion Device"); columns.Bound(o => o.Status); columns.Bound(o => o.Energy_Range).Title("Energy Range"); columns.Command(command => { command.Destroy(); }).Width(50); }) .ToolBar(toolbar => toolbar.Create()) .Editable(editable => editable.Mode(GridEditMode.PopUp)) .Pageable() .Sortable() .DataSource(dataSource => dataSource .Server() .Model(model => model.Id(o => o.ID)) .Create(create => create.Action("Create", "Grid")) .Read(read => read.Action("Index", "Grid")) .Update(update => update.Action("Edit", "Grid")) .Destroy(destroy => destroy.Action("Delete", "Grid")) ) )Controller: (only some methods are in place so far)
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using MyLibrary;namespace MyProject.Controllers{ public class BeamlinesController : Controller { // // GET: /Beamlines/ public ActionResult Index() { using (MyEntities context = new MyEntities()) { return View(context.Beamlines.ToList()); } } // // GET: /Beamlines/Details/5 public ActionResult Details(int id) { return View(); } // // GET: /Beamlines/Create public ActionResult Create() { return View(); } // // POST: /Beamlines/Create [HttpPost] public ActionResult Create(Beamline beamline) { try { // TODO: Add insert logic here return RedirectToAction("Index"); } catch { return View(); } } // // GET: /Beamlines/Edit/5 public ActionResult Edit(int id) { using (MyEntities context = new MyEntities()) { var beamline = context.Beamlines.Single(p => p.ID == id); return View(beamline); } } // // POST: /Beamlines/Edit/5 [HttpPost] public ActionResult Edit(int id, FormCollection collection) { using (MyEntities context = new MyEntities()) { var beamline = context.Beamlines.Single(p => p.ID == id); TryUpdateModel(beamline); if (ModelState.IsValid) { context.SaveChanges(); return RedirectToAction("Index"); } return View(beamline); } } // // GET: /Beamlines/Delete/5 public ActionResult Delete(int id) { return View(); } // // POST: /Beamlines/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here return RedirectToAction("Index"); } catch { return View(); } } }}