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

"Ajax Select" method is invoked if "Server Select" method returns no record

3 Answers 61 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.
rino
Top achievements
Rank 1
rino asked on 10 Dec 2010, 12:15 AM

I am running this same example http://demos.telerik.com/aspnet-mvc/grid/filtering in debug mode. I am using Q3 2010. Here is the controller:

public ActionResult Filtering(string startsWith)
        {
            ViewData["startsWith"] = startsWith ?? "Paul";
            return View(GetOrders());
        }
  
        [GridAction]
        public ActionResult _Filtering()
        {
            return View(new GridModel<Order>
            {
                Data = GetOrders()
            });
        }

If action Filtering (server) returns no record, action _Filtering (ajax) is invoked.  Why is that? Not sure if this is by design, but what if I dont want to the Ajax select method being invoked? Is there a work around?

To reproduce, enter "Q" in the textbox and press Apply.

3 Answers, 1 is accepted

Sort by
0
jayanth
Top achievements
Rank 1
answered on 19 Dec 2010, 04:24 PM
Hey, I had the same error in my application while using the grid, I am not sure if this one could be a work around, its the binding you apply to the grid that has made the difference, atleast in my case, I had this error when I binded the grid with a stored procedure result directly as shown in the above action method, instead I used a ViewModel, and it worked even if the server method was returning no records, the ajax select was not invoked.
0
rino
Top achievements
Rank 1
answered on 24 Dec 2010, 04:55 AM
Hi jayanth,
Can you provide more details on how you used ViewModel in this case? Thanks!
0
jayanth
Top achievements
Rank 1
answered on 25 Dec 2010, 04:28 PM
Here's a link on How to create ViewModels,
http://stephenwalther.com/blog/archive/2009/04/13/asp.net-mvc-tip-50-ndash-create-view-models.aspx

in this case, what i had previously was my grid binded to a stored procedure directly, and i had a databinding ajax select action for it, called _updateGrid, something like this
Html.Telerik().Grid<usp_storedproc>().DataBinding(bin => bin.Ajax().Select("_updateGrid", "Home"))
when the view was rendered, the controller action _updateGrid, which is a grid specific action was being invoked, and pages such as _updateGrid.aspx etc were being searched to render.

Later, I made a strongly typed view which inherits from a viewmodel the properties it needs, so in the viewmodel i have something like
public IList<usp_storedproc> gridList;

Now, in my view as it inherits the above viewmodel
Html.Telerik().Grid(Model.gridList).SameAsAbove

That did it for me, the action _updateGrid was not invoked even if the initial server select had no records. as i said im not sure if this is a work around cause I am still a beginner with telerik, hope this helps you..

Jay
Tags
Grid
Asked by
rino
Top achievements
Rank 1
Answers by
jayanth
Top achievements
Rank 1
rino
Top achievements
Rank 1
Share this question
or