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

[Solved] MVC Ajax Databind cant make it work

0 Answers 16 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Hoang Phuong
Top achievements
Rank 1
Hoang Phuong asked on 24 Nov 2011, 04:55 PM
Hello,

I am trying to databind a grid using ajax. When I am trying to run the code while debugging none of the commands like Update are firing in my controller. 

Here is my code - any ideas why the controller functions are not called when i click "Update". Furthermore, why the _AjaxSelect() is not fired either to populate the grid with data? 

Here is my View:

@(Html.Telerik().Grid<ADTool.Models.Monthly_Workorders>()
        .Name("Test")
        .ToolBar(commands => commands.Insert())
        .DataKeys(datakeys =>
        {
            datakeys.Add(p => p.monthly_workorder_year).RouteKey("monthly_workorder_year");
            datakeys.Add(p => p.monthly_workorder_month).RouteKey("monthly_workorder_month");
            datakeys.Add(p => p.project_id).RouteKey("project_id");
            datakeys.Add(p => p.workorder_id).RouteKey("workorder_id");
            datakeys.Add(p => p.department_id).RouteKey("department_id");
        })
        .Columns(columns =>
        {
            columns.Bound(c => c.project_id).Title("project").Width(10);
            columns.Bound(c => c.workorder_id).Title("work order").Width(10);
            columns.Bound(c => c.department_id).Title("department").Width(10);
            columns.Bound(c => c.monthly_workorder_year).Title("year").Width(5);
            columns.Bound(c => c.monthly_workorder_month).Title("month").Width(5);
 
            columns.Bound(c => c.ac_hours).Width(10).Title("ac");
            columns.Bound(c => c.correction_hours).Width(10).Title("extra");
            columns.Bound(c => c.etc_hours).Width(10).Title("etc");
            columns.Bound(c => c.eac_hours).Width(10).Title("eac");
            columns.Bound(c => c.payment_plan).Width(10).Title("plan");
            columns.Bound(c => c.hour_rate).Width(10).Title("rate");
            columns.Command(commands =>
            {
                commands.Edit();
                commands.Delete();
            }).Width(200).Title("Commands");
        })
        .DataBinding(dataBinding => dataBinding
            .Ajax()
                .Select("_AjaxSelect", "Test")
                .Insert("_AjaxInsert", "Test")
                .Update("_AjaxSave", "Test")
                .Delete("_AjaxSelect", "Test")
                )
        .Filterable()
        .Sortable()
        .Pageable()
        .Groupable()
)


Here is my controller:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;
using ADTool.Models;
 
namespace ADTool.Controllers
{
    public class TestController : Controller
    {
        private ADToolEntities db = new ADToolEntities();
 
        public ActionResult Index()
        {
            return View();
        }
 
        [GridAction]
        public ActionResult _AjaxSelect()
        {
            return View(new GridModel(db.Monthly_Workorders));
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _AjaxSave(int id)
        {
            return View(new GridModel(db.Monthly_Workorders));
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public ActionResult _AjaxInsert()
        {
            return View(new GridModel(db.Monthly_Workorders));
        }
    }
}


Thanks in advance.


Tags
Grid
Asked by
Hoang Phuong
Top achievements
Rank 1
Share this question
or