Kendo Grid AJAX绑定不更新MVC4

时间:2014-08-04 20:12:53

标签: asp.net ajax kendo-ui kendo-grid

我正在尝试让我的网格更新为选择加入状态,但是当我点击更新时,不会发生任何操作。我使用ajax绑定模型和实体框架。当我点击取消时,它将遵循此方法。因为其他所有功能和编译,我不确定我错过了什么。

查看

<div class="row">
<h2>PQA Opt-In</h2>

<br />

 @(Html.Kendo().Grid<TelerikMvcApp1.Models.PQAViewModel>()
    .Name("grid")
     .Columns(columns =>
    {
        columns.Bound(opt => opt.Jobber).Width(90);
        columns.Bound(opt => opt.Dealer).Width(95);
        columns.Bound(opt => opt.OptInd).Width(110);
        columns.Bound(opt => opt.establish_date_time);
        columns.Bound(opt => opt.establish_id);
        columns.Command(commands =>
            {
                commands.Edit();
            }).Title("Commands").Width(200); 
       })
            .DataSource(datasource => datasource
                .Ajax()
                .Model(model =>
                    {
                        model.Id(opt => opt.Jobber);
                        model.Field(opt => opt.Jobber).Editable(false); 
                        model.Field(opt => opt.Dealer).Editable(false);
                        model.Field(opt => opt.establish_date_time).Editable(false);
                        model.Field(opt => opt.establish_id).Editable(false);
                    })
                .PageSize(20)
                .Read(read => read.Action("ProductQualityFileFull_Read", "PQA"))
                .Update(update => update.Action("Opt_Update", "PQA"))
              )
    .Editable(editable => editable.Mode(GridEditMode.InLine))
   .Filterable()
    .Pageable() 
 )  



  </div>

控制器

sing System;
using System.Linq;
using System.Web.Mvc;
using System.Data; 
using System.Data.Entity; 
using TelerikMvcApp1.Models;
using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

 namespace TelerikMvcApp1.Controllers
{
public class PQAController : Controller
{

    public ActionResult Baseline()
    {
        return View();
    }

    public ActionResult ProductQualityFileFull_Read([DataSourceRequest] DataSourceRequest  
 request)
    {
        using (var pqa = new PQAEntities())
        {
            IQueryable<ProductQualityFileFull> opt = pqa.ProductQualityFileFulls;
            DataSourceResult result = opt.ToDataSourceResult(request, ProductQualityFileFull => 
new PQAViewModel
            {
                Jobber = ProductQualityFileFull.Jobber,
                Dealer = ProductQualityFileFull.Dealer,
                OptInd = ProductQualityFileFull.OptInd,
                establish_date_time = ProductQualityFileFull.establish_date_time,
                establish_id = ProductQualityFileFull.establish_id

            });
            return Json(result);
        }
    }

    public ActionResult UpdateOptIn()
    {

        return View();

    }



    public ActionResult Opt_Update([DataSourceRequest] DataSourceRequest request, 
PQAViewModel opt)
    {
        if (ModelState.IsValid)
        {
            using (var pqa = new PQAEntities())
            {
                var entity = new ProductQualityFileFull
            {
                Jobber = opt.Jobber,
                Dealer = opt.Dealer,
                OptInd = opt.OptInd,
                establish_date_time = opt.establish_date_time,
                establish_id = opt.establish_id
            };

                pqa.ProductQualityFileFulls.Attach(entity);

                pqa.Entry(entity).State = EntityState.Modified;

                pqa.SaveChanges();
            }
        }

        return Json(new[] { opt }.ToDataSourceResult(request, ModelState));

    }
  }
} 

模型

namespace TelerikMvcApp1.Models
{
 public class PQAViewModel
 {
    public string Jobber { get; set; }
    public int Dealer { get; set; }
    public int OptInd { get; set; }
    public DateTime establish_date_time { get; set; }
    public string establish_id { get; set; }
 }
}

1 个答案:

答案 0 :(得分:0)

您已将所有列都设为不可编辑 - 这意味着您不会对模型进行任何更改。如果没有进行任何更改 - 则不会执行更新请求。对模型进行更改并触发更新。