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

[Solved] ajaxRequest fires, but OnDataBound doesnt get called

2 Answers 117 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.
Ben
Top achievements
Rank 1
Ben asked on 12 Jul 2011, 12:29 AM

Hi,
NOTE: removed the clientEvent OnDataBound from current Grid.

I cant get my grid to refresh. Controller Action gets called during ajax request, but grid doesnt refresh. Fiddler shows proper GridModel (Json) data returned. Please help.
Ben

Controller
************************************************************
       [GridAction(EnableCustomBinding = true)]
        public ActionResult _CompanyIndex(GridCommand command, int? id = 0)
        {
            var _list = new List<MasterContactCompanyViewModel>();
            if(id.Value > 0)
            {
                var _companies = _contactCompanyRepository.GetByMasterContactId(id.Value);

                _list = MasterContactCompanyViewModelFactory.ToMasterContactCompanyViewModel(_companies);
            }

            var _count = _list.Count();
            
            ViewData["total"] = _count;
            ViewData["pageSize"] = command.PageSize;
            ViewData["pageTo"] = command.Page;

            return View(new GridModel { Data = _list, Total = _count });
        }


******************************************************************************
View
*******************************************************************************
@(Html.Telerik().Grid(Model.Companies)
    .Name("grdCompanyList")
    .DataKeys(keys => keys.Add(o => o.MnetCompanyID))
    .ToolBar(commands => commands.Template(@<text>@if (Model.Companies == null || Model.Id > 0 && Model.Companies.Count > 0){<button type="button" title="Edit" onclick="addCompany();" class="t-button">Add new company</button>}</text>))
    .Columns(columns =>
    {
        columns.Bound(o => o.MnetCompanyID).Width(150);
        columns.Bound(o => o.CompanyName);
        columns.Bound(o => o.CustomerNumbers).Template(o => CustomerNumbersTemplate(this, o.CustomerNumbers)).Sortable(false);
        columns.Bound(o => o.MnetCompanyID).Title("").Sortable(false).Width(150)
            .Template(@<text>@if (Model.Id > 0 && Model.Companies.Count > 1){<button type="button" title="Delete" onclick="deleteCompany(@item.MnetCompanyID);" class="t-button">                                 Delete</button>}</text>)
            .ClientTemplate("<button type='button' title='Delete' onclick='deleteCompany(<#= MnetCompanyID #>);' <#= Model.Id > 0 && Model.Companies.Count > 1 ? \"style='display:block'\" : \"\" #> class='t-button'>Delete</button>");
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_CompanyIndex", "MasterContact", new {id = Model.Id}).Enabled(true))
    .NoRecordsTemplate("No Results")
    .Pageable(page => page.PageSize(20).Position(GridPagerPosition.Bottom))
    .Scrollable()
    .Sortable()
    .EnableCustomBinding(true)
)

************************************************************************
javascript refresh
**********************************************************************
var grid = $("#grdCompanyList").data("tGrid");
grid.ajaxRequest();



2 Answers, 1 is accepted

Sort by
0
Ammar
Top achievements
Rank 1
answered on 04 Aug 2011, 10:50 PM
I am facing the same problem, please respond.
0
charles
Top achievements
Rank 1
answered on 26 Aug 2011, 04:47 AM
Ben,
You don't have your GridAction decorated with the [AcceptVerbs(HttpVerbs.Post)] or the less verbose [HttpPost] attribute.  Put that right above your [GridAction] attribute and see if it fixes your issue. 

If that doesn't work, I've had trouble doing ajax binding while passing in a route value to the GridAction before...if you have the Id available when you open the View, you may want to pass it in to the View as a route value, and then get that route value when you bind to the grid. 

Try adding the [HttpPost] attribute first...if it doesn't help, I can show you my workaround for getting the route value.

Thanks,
Will
Tags
Grid
Asked by
Ben
Top achievements
Rank 1
Answers by
Ammar
Top achievements
Rank 1
charles
Top achievements
Rank 1
Share this question
or