This is a migrated thread and some comments may be shown as answers.
Ajax binding of telerik mvc grid with async methods
7 Answers 123 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
test
Top achievements
Rank 1
test asked on 14 Jul 2011, 11:08 AM
I am trying to bind my Telerik grid through Ajax with Async method. As described in the help file, I have created a replica of the Async(Begin and Complete) method for Telerik grid with the [GridModel] attribute. I have registered the route in the class. However, I get an error that
"A route named 'AjaxBindingCompleted' could not be found in the route collection.
Parameter name: name"
in the .cshtml class.
How do i solve this error? I am binding the async method as follows:
List<Account> posquity = Model.ListOfAllPositions.FindAll(Account accPosDetails) ;
         Html.Telerik().Grid(posquity).Name("grdPersonView")
             .DataBinding(databinding => databinding.Ajax()
             .Select("AjaxBinding","Person"))
                                                  .Columns(columns =>
                                                  {
 
                                                      columns.Bound(p => p.Number);
                                                      columns.Bound(p => p.Value);
                                                      columns.Bound(p => p.Name).Width(100);
in the controller i 've 2 methods defined:
[GridAction]
       public ActionResult AjaxBindingCompleted(AccountPositions accountPositions, Dictionary<string, CMSContent> cmsContent, bool hasServiceError)
       {
           MarginViewModel viewModel = new MarginViewModel();
           List<MarginViewModel> viewModelList = new List<MarginViewModel>();
          
                    viewModelList.Add(viewModel);
               
               return View(new GridModel(viewModelList));                                
                       }
public void AjaxBindingAsync(AccountInput account)
        {
........
}

7 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Jul 2011, 12:30 PM
Hello Test Test,

UPDATED:

You should add the GridAction attribute to the  method which ends with Async. When configuring the grid specify the method name without "Async".

 Find attached a working project.

Greetings,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
test
Top achievements
Rank 1
answered on 14 Jul 2011, 01:05 PM
I solved this problem. The route was not registered properly. Now the problem that i m facing is that on page refresh i get a javascript error : 'Error: The requested URL didnot return JSON'. Is it necessary to return JSON from the controller? I am returning IEnumerable list to the view
0
test
Top achievements
Rank 1
answered on 14 Jul 2011, 01:15 PM
Thanks for the quick response. As mentioned in my previous post, I get a JSON related error on page refresh and I am not passing any JSON data. Do you get a similar error? Also, I have rectified the method name in the grid. I have changed it to match the syntax "action","controller"
0
Atanas Korchev
Telerik team
answered on 14 Jul 2011, 01:34 PM
Hello Test,

 Did you check the updated project? I updated my reply shortly after posting.

Greetings,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
test
Top achievements
Rank 1
answered on 18 Jul 2011, 05:38 AM
Hi,

I checked the project that you had uploaded. I have followed the same steps for implementation. The only difference is that while you are using a single method "index" for binding and paging, I am using two methods. I am using Index for basic binding and AjaxBinding for paging. I can't use a single method "index" for both the operations as Index is being used by other grids on the page.

The problem is that when i click the next page, I get an error 404 - Url could not be found. Could I be getting this error because I am using 2 different methods here? Can you give some insight here?

Thanks.
0
Atanas Korchev
Telerik team
answered on 18 Jul 2011, 08:22 AM
Hello Test,

 I am not sure what went wrong at your side.To repeat you need to do the following when doing ajax binding with async methods:

1. Create two methods e.g. SelectAsync and SelectComplete.
2. Configure the grid to bind to "Select" (not SelectAsync or SelectComplete):

.DataBinding(dataBinding=> dataBinding.Ajax().Select("Select", "Home"))


3. Add the [GridAction] method to SelectAsync:
[GridAction]
public void SelectAsync()
{
}



4. Use GridModel in SelectComplete:
public ActionResult SelectCompleted()
{
    return View(new GridModel(new[] { new Product { ID = 1, Name = "Product 1" } }));
}

If you need further assistance please modify the attached project so it mimics your real setup.

Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
test
Top achievements
Rank 1
answered on 19 Jul 2011, 06:29 AM
Thanks for providing a detailed explanation. I have resolved the problem. The problem was in the type of the data being returned by the Async method.

Tags
Grid
Asked by
test
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
test
Top achievements
Rank 1
Share this question
or