Hasanuzzaman
Hasanuzzaman

Reputation: 1862

Why Kendo Ui Grid is not fire Update Action in MVC 4?

I create Kendo UI Grid that can Create, Update and Delete Data. But it is not fire Update Action in my Controller.

Here is My Code :

<script src="~/Scripts/Kendo/jquery.min.js"></script>
<script src="~/Scripts/Kendo/kendo.all.min.js"></script>
<script src="~/Scripts/Kendo/kendo.aspnetmvc.min.js"></script>

@(Html.Kendo().Grid<SkuMetadata>()
  .Name("Grid")
  .Columns(colums =>
               {
                   colums.Bound(p => p.CompanyName).Width(100);
                   colums.Bound(p => p.BrandName).Width(100);
                   colums.Bound(p => p.ProductName).Width(100);
                   colums.Bound(p => p.SkuName).Groupable(false).Width(100);
                   colums.Command(command => { 
                       command.Edit();
                       command.Destroy(); }).Width(160);
               })
  .ToolBar(toolbar => toolbar.Create())
  .Editable(editable => editable.Mode(GridEditMode.PopUp))
      .Groupable()
      .Pageable()
      .Sortable()
      .Scrollable()
      .Filterable()

  .HtmlAttributes(new { style = "height: 500px;" })
  .DataSource(dataSource =>
              dataSource
                  .Ajax()     
                  .Batch(true)
                  .ServerOperation(false)
                  .PageSize(100)
                  .Events(events => events.Error("error_handler"))
                  .Model(model => model.Id(p => p.SkuId))
                  .Create(update => update.Action("CreateProducts", "Product"))
                  .Update(update => update.Action("UpdateProducts", "Product").Type(HttpVerbs.Post))
                  .Destroy(destroy => destroy.Action("DeleteProducts", "Product"))
                  .Read(read => read.Action("GetAllProducts", "Product"))))

My Action Is :

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult UpdateProducts([DataSourceRequest] DataSourceRequest request, SkuMetadata skuMetadata)
    {
        return Json(_basicUnit.Skus.GetAllSku().ToDataSourceResult(request));
    }
    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult DeleteProducts([DataSourceRequest] DataSourceRequest request, SkuMetadata skuMetadata)
    {

        return Json(_basicUnit.Skus.GetAllSku().ToDataSourceResult(request));
    }

Create and Delete Works fine. I dont understand Why Update is not working. Am i miss any reference or what i doing wrong?

Upvotes: 2

Views: 8726

Answers (5)

Victor Boaventura
Victor Boaventura

Reputation: 1

In your render action you must send ID value in model.

[PopulateViewData("PopulateViewData")]
public virtual ActionResult Novo()
{
    domain = ...;
    var model = new Model
    {
        Id = model.Id,
        Propertyx = model.PropertyX,
        ...
    };
 return View(model);
 }

Upvotes: 0

bill
bill

Reputation: 1

you have to change ServerOperation(false) to ServerOperation(true)

Upvotes: 0

Timur  Shahbanov
Timur Shahbanov

Reputation: 425

Use this

 .DataSource(dataSource =>
          dataSource
              .Ajax()     
              .Batch(true)
              .ServerOperation(false)
              .PageSize(100)
              .Events(events => events.Error("error_handler"))
         ---->**.Model(model => { model.Id(p => p.ID); model.Field(p => p.ID).DefaultValue(16000000); })** <--------
              .Create(update => update.Action("CreateProducts", "Product"))
              .Update(update => update.Action("UpdateProducts", "Product").Type(HttpVerbs.Post))
              .Destroy(destroy => destroy.Action("DeleteProducts", "Product"))
              .Read(read => read.Action("GetAllProducts", "Product"))))

Upvotes: 4

Vetal
Vetal

Reputation: 29

Try mark action with [GridAction] attribute.

And may be you must write actions something like:

[AcceptVerbs(HttpVerbs.Post)]  
[GridAction]  
public ViewResult(...)  
{  
//do what you need..and if .ToDataSourceResult(..) return IEnumerable try write  
var model = _basicUnit.Skus.GetAllSku().ToDataSourceResult(request);  
return View(new GridModel(model));  
} 

Upvotes: 0

Brett McCarty
Brett McCarty

Reputation: 399

I would first take the grid out of batch edit mode to see if you can get the update action to fire after you update the record in the popup.

Upvotes: 0

Related Questions