0

我有页面 mvc cshtml

它包含一个开始beginform:

@using (Html.BeginForm("ValiderLeChangement", "FichePersonnel", FormMethod.Post , new { id = "FormValider" }  ))
{
}

在这个表格中,我将网格剑道 ui 放在了我想使用的剑道网格中

在 Kendo UI DEMO ( http: //demos.kendoui.c​​om/web/grid/editing-inline.html )中创建添加和删除示例

我对创建、删除或编辑的操作有疑问,不要在服务器上触发

我的代码是:

@(Html.Kendo().Grid(Model.ListeContact)
    .Name("Grid")
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .ToolBar(toolbar => toolbar.Create())
    .Columns(columns =>
    {
        columns.Bound(p => p.Nom).Title("Nom").Width(20);
        columns.Bound(p => p.Prenom).Title("Prenom").Width(20);

        //columns.Bound(p => p.Lien.Libelle).Title("Lien").Width(20).ClientTemplate(????? );
        columns.Bound(p => p.Lien.Libelle).Title("Lien").Width(20);

        columns.Bound(p => p.Tel).Title("Telephone").Width(20);

        columns.Command(command => { command.Edit(); }).Width(30);
        columns.Command(command => { command.Destroy(); }).Width(30);
      /////////  columns.Bound(p => p.IdContact).ClientTemplate("#= Delete(data) #").Title("Supprimer").Width(5);
    })
    .Sortable()
    .DataSource(dataSource => dataSource
    .Ajax()
    .Batch(true)
    .ServerOperation(true)
    .Events(events => events.Error("error_handler"))
    .Read(Read => Read.Action("ListeContact_Read", "FichePersonnel"))
        .Model(model => model.Id(p => p.IdContact))
        .Create(create => create.Action("EditingInline_Create", "FichePersonnel"))
        .Update(update => update.Action("EditingInline_Update", "FichePersonnel"))
        .Destroy(delete => delete.Action("EditingInline_Destroy", "FichePersonnel"))

    )
)
4

1 回答 1

0

你是如何实现你的控制器动作方法的?它是否处理请求并正确返回?它应该是这样的:

public ActionResult EditingInline_Create([DataSourceRequest] DataSourceRequest request, ProductViewModel product)
    {
        if (product != null && ModelState.IsValid)
        {         
            SessionProductRepository.Insert(product);                                 
        }

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

注意第一个参数 DataSourceRequest 和返回类型 Json。也许这就是你所缺少的。我还注意到您表示的是 ServerOperation(true)。据我了解,如果您按原样使用 AJAX 绑定,则不需要这样做。

编辑:所以对于控制器代码,是这样的:

    public partial class TextosController : EditorImageBrowserController
{
    public ActionResult ReadTextos([DataSourceRequest]DataSourceRequest request)
    {
        CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));

        IQueryable<Texto> textos = modelo.Textos;
        DataSourceResult resultado = textos.ToDataSourceResult(request);
        ViewData["Textos"] = textos;
        return Json(resultado, JsonRequestBehavior.AllowGet);
    }
    public ActionResult CreateTexto([DataSourceRequest]DataSourceRequest request, Texto texto)
    {
        if (ModelState.IsValid)
        {
            CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));

            // Create a new Product entity and set its properties from the posted ProductViewModel
            Texto entity = new Texto
            {
                TextoID = texto.TextoID,
                Titulo = texto.Titulo,
                Corpo = texto.Corpo,
                IsPrivado = texto.IsPrivado,
                TipoTextoID = texto.TiposTexto != null ? texto.TiposTexto.TipoTextoID : texto.TipoTextoID,
                TiposTexto = texto.TiposTexto
            };
            modelo.AddToTextos(entity);
            // Insert the entity in the database
            modelo.SaveChanges();
            // Get the ProductID generated by the database
            texto.TextoID = entity.TextoID;
            return Json(new[] { entity }.ToDataSourceResult(request, ModelState));
        }
        // Return the inserted product. The grid needs the generated ProductID. Also return any validation errors.
        return Json(new[] { texto }.ToDataSourceResult(request, ModelState));
    }

    public ActionResult UpdateTexto([DataSourceRequest]DataSourceRequest request, Texto texto)
    {
        if (ModelState.IsValid)
        {
            CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));

            // Create a new Product entity and set its properties from the posted ProductViewModel
            var entity = new Texto
            {
                TextoID = texto.TextoID,
                Titulo = texto.Titulo,
                Corpo = texto.Corpo,
                IsPrivado = texto.IsPrivado,
                TipoTextoID = texto.TiposTexto != null ? texto.TiposTexto.TipoTextoID : texto.TipoTextoID,
                TiposTexto = texto.TiposTexto
            };
            // Attach the entity
            modelo.AttachTo("Textos", entity);
            modelo.UpdateObject(entity);
            // Update the entity in the database
            modelo.SaveChanges();
            return Json(new[] { entity }.ToDataSourceResult(request, ModelState));
        }
        // Return the updated product. Also return any validation errors.
        return Json(new[] { texto }.ToDataSourceResult(request, ModelState));
    }

    public ActionResult DestroyTexto([DataSourceRequest]DataSourceRequest request, Texto texto)
    {
        if (ModelState.IsValid)
        {
            CostSimulatorModel modelo = new CostSimulatorModel(new Uri(@"http://localhost:53212/CostSimulatorModelService.svc/"));

            // Create a new Product entity and set its properties from the posted ProductViewModel
            var entity = new Texto
            {
                TextoID = texto.TextoID
            };
            // Attach the entity
            modelo.AttachTo("Textos", entity);
            // Delete the entity
            modelo.DeleteObject(entity);

            // Delete the entity in the database
            modelo.SaveChanges();
            return Json(new[] { entity }.ToDataSourceResult(request, ModelState));
        }
        // Return the removed product. Also return any validation errors.
        return Json(new[] { texto }.ToDataSourceResult(request, ModelState));
    }
}
于 2013-08-06T08:58:07.283 回答