Chandra Bhattarai
Chandra Bhattarai

Reputation: 97

kendogrid update not being called

I am facing trouble in mvc c# kendo ui grid. i am trying to call the controller action from kendo update batch update method i am having problem My mvc view is like this .It work fine on calling 'read' but while updating(saving all batch) then it is not hitting in controller:

   @(Html.Kendo().Grid(Model.oldList)
          .Name("grid")
          .Columns(columns =>
          {
              columns.Bound(m => m.IsNewString).HeaderHtmlAttributes(new { style = "text-align:center;" }).Title("Data").Encoded(false).Width(80); ;
              columns.Bound(m => m.Id).HeaderHtmlAttributes(new { style = "text-align:center;" }).Title("Code").Encoded(false).Width(80);
              columns.Bound(m => m.Name).HeaderHtmlAttributes(new { style = "text-align:center;" }).Title("Business Name").Encoded(false).Width(80);
              columns.Bound(m => m.Address.Address1).HeaderHtmlAttributes(new { style = "text-align:center;" }).Title("Address1").Encoded(false).Width(80);
              columns.Bound(m => m.Address.Address2).HeaderHtmlAttributes(new { style = "text-align:center;" }).Title("Address2").Encoded(false).Width(80);
              columns.Bound(m => m.Address.Country).HeaderHtmlAttributes(new { style = "text-align:center;" }).Title("Country").Encoded(false).Width(80);
              columns.Command(commands =>
              {
                  commands.Destroy(); 
              }).Title("Commands").Width(200);
          })
          .ToolBar(toolbar =>
          {
              //toolbar.Create(); 
              toolbar.Save(); 
          })
          .Editable(editable => editable.Mode(GridEditMode.InCell)) 
          .DataSource(dataSource =>
              dataSource.Ajax()
                .Batch(true) // Enable batch updates
                .Model(model =>
                {
                    model.Id(m => m.Id); 
                    model.Field(m => m.Id).Editable(false); 
                })
                //.Create(create => create.Action("Products_Create", "Home"))
                .Read(read => read.Action("LoadCompareList", "Home", new { clientId = clientid, templateId = templateid })) 
                                .Update(update => update.Action("test", "Home"))  

          )
          .Pageable()
                    )

My controller action is like this :

     [HttpPost]
        public ActionResult test([DataSourceRequest]DataSourceRequest request,IEnumerable<DetailsDTO> products)
        {
            return View();
        }

But this action is not firing. I don't know what is happening.

Upvotes: 3

Views: 3418

Answers (3)

okeziestanley
okeziestanley

Reputation: 349

I had this same issue and after struggling with it for a whole night, I realized that kendo requires that the model.Id value be present and unique. In my case this wasn't true because I was manually populating the grid from code (not from db), so I used another property that is guaranteed to have unique values as Id, and it worked.

Model(model =>
      {
        model.Id(x => x.MetreId);
}

Upvotes: 2

codingbadger
codingbadger

Reputation: 44032

You need to change your Controller method to be:

[HttpPost]
public ActionResult test([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<DetailsDTO> products)
{
        return View();
}

Also ensure that you have referenced the script kendo.aspnetmvc.min.js

Upvotes: 0

M. Altmann
M. Altmann

Reputation: 726

changing

.Update(update => update.Action("test", "Home"))  

to

.Update(update => update.Action("test", "Home").Type(HttpVerbs.Post))  

does the trick in my application. Also i'm using the attribute

[AcceptVerbs(HttpVerbs.Post)]

in my controller.

Addition:

An other reason could be the model. I had to change my method to something like this:

public async Task<ActionResult> UpdatePackageList([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<MyClass> products)

Upvotes: 1

Related Questions