This is a migrated thread and some comments may be shown as answers.

Basic functions of Grid not working

6 Answers 331 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 12 Dec 2012, 03:31 PM
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:
@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();
            }
        }
    }
}

6 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 14 Dec 2012, 09:09 AM
Hi Stephen,

The Grid is navigating according to its configuration, which seems wrong, because the controller is not called "Grid".

.Create(create => create.Action("Create", "Grid"))
.Read(read => read.Action("Index", "Grid"))
.Update(update => update.Action("Edit", "Grid"))
.Destroy(destroy => destroy.Action("Delete", "Grid")

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Stephen
Top achievements
Rank 1
answered on 14 Dec 2012, 06:08 PM
I knew it was going to be something stupid that I missed!  Thank you!
0
Stephen
Top achievements
Rank 1
answered on 21 Feb 2013, 09:04 PM
Hello again,

Is there a way to use a custom template with the adding/editing so that I can display my fields differently?  The inline doesn't work for me because I have too many fields to show and the popup editor doesn't work either for the same reason.  How can I create a custom control? for my adding/editing within the grid?

Thanks,

Steve
0
Dimo
Telerik team
answered on 25 Feb 2013, 09:05 AM
Hello Stephen,

The described functionality is described in the documentation...

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/editor-templates

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq#how-do-i-create-a-custom-popup-editor?

The second link points to a code library project and there is a related example in the offline Kendo UI MVC Grid demos - "Editing, Custom Editor".

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Stephen
Top achievements
Rank 1
answered on 26 Feb 2013, 03:43 PM
Is there a problem with the Kendo UI Docs right now?  I keep getting 404 errors on the links above and any other page I try to get to within the Docs.
0
Dimo
Telerik team
answered on 27 Feb 2013, 08:22 AM
Hi Stephen,

I am afraid yes, sorry about that. Please try again, they should work now.

Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Stephen
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or