Telerik MVC 网格重新绑定崩溃

发布于 2024-12-22 06:44:19 字数 2508 浏览 3 评论 0原文

按照 Telerik Mvc Grid Demo 中设置的插入和编辑模式,一切正常,直到到达控制器方法返回的位置。

请参阅:http://demos.telerik.com/aspnet-mvc /razor/Grid/EditingAjax?theme=vista

这些方法调用我的存储库函数,成功更新数据库;但是,演示中的返回代码如下所示,

[AcceptVerbs(HttpVerbs.Post)]        
[CultureAwareAction]        
[GridAction]        
public ActionResult _InsertAjaxEditing()
{
    EditableProduct product = new EditableProduct();            
    if (TryUpdateModel(product)) {
        SessionProductRepository.Insert(product);
    }            
    return View(new GridModel(SessionProductRepository.All()));        
}

一切都可以达到返回行,所以我尝试了:

  1. return View(new GridModel(myTypeRepository.All);
  2. return View(new GridModel(myTypeRepository.All.ToList());
  3. return视图(新的GridModel(myTypeRepository.All.ToArray());
  4. 返回视图(新的GridModel(myTypeRepository.All);
  5. 返回视图(新GridModel(myTypeRepository.All.ToList());
  6. 返回视图(new GridModel(myTypeRepository.All.ToArray());
  7. 返回视图(GridModel(myTypeRepository.All))
  8. 返回视图(GridModel(myTypeRepository.All.ToList()))
  9. return View(GridModel(myTypeRepository.All.ToArray()))

所有这些都导致无法跟踪异常,因为它指向 Telerik 文件: 现在,因为它出现在方法的末尾,所以

我无法确定它是返回语句还是 html.Telerik.Grid。但是,正如我所说,我遵循了演示中的模式:

@(Html.Telerik().Grid<BerettaFarms.Models.FoodKind>()
    .Name("myName")
    .ToolBar(commands => commands.Insert())
    .DataKeys(keys => keys.Add(c => c.myTypeId))
    .DataBinding(dataBinding => {
        dataBinding.Ajax()
            .Select("SelectAjaxEditing", "myController")
            .Insert("InsertAjaxEditing", "myController")
            .Update("SaveAjaxEditing", "myController")
            .Delete("DeleteAjaxEditing", "myController");
    })       
    .Columns(columns => {            
        columns.Bound(o => o.Name).Width(200);            
        columns.Bound(o => o.Description).Width(400);
        columns.Command(commands => {
            commands.Edit();
            commands.Delete();
        }).Width(200);  
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("AjaxIndex", "myController"))
    .Editable(editing => editing.Mode(GridEditMode.InLine))               
    .Sortable()
    .Scrollable(h => h.Height("700px"))       
    .Groupable()        
    .Filterable()
) 

所以如果有人知道为什么重新绑定失败吗?或者如果是其他原因,请告诉我。

Following the patten as set out in the Telerik Mvc Grid Demo for inserting and editing, everything works up until it gets to the point where the controller method returns.

See: http://demos.telerik.com/aspnet-mvc/razor/Grid/EditingAjax?theme=vista

The methods call into my repository functions which successfully update the database; however, the return code in the demo as shown here

[AcceptVerbs(HttpVerbs.Post)]        
[CultureAwareAction]        
[GridAction]        
public ActionResult _InsertAjaxEditing()
{
    EditableProduct product = new EditableProduct();            
    if (TryUpdateModel(product)) {
        SessionProductRepository.Insert(product);
    }            
    return View(new GridModel(SessionProductRepository.All()));        
}

Everything works up to the return line, so I tried:

  1. return View(new GridModel(myTypeRepository.All);
  2. return View(new GridModel(myTypeRepository.All.ToList());
  3. return View(new GridModel(myTypeRepository.All.ToArray());
  4. return View(new GridModel(myTypeRepository.All);
  5. return View(new GridModel(myTypeRepository.All.ToList());
  6. return View(new GridModel(myTypeRepository.All.ToArray());
  7. return View(GridModel(myTypeRepository.All))
  8. return View(GridModel(myTypeRepository.All.ToList()))
  9. return View(GridModel(myTypeRepository.All.ToArray()))

All of which resulted in an exception that could not be followed because it points to the Telerik file: GridActionAttribute.cs.

Now because it occurs at the end of the method, I can't be sure that it is the return statment or the html.Telerik.Grid. However, as I said I followed the pattern in the demo:

@(Html.Telerik().Grid<BerettaFarms.Models.FoodKind>()
    .Name("myName")
    .ToolBar(commands => commands.Insert())
    .DataKeys(keys => keys.Add(c => c.myTypeId))
    .DataBinding(dataBinding => {
        dataBinding.Ajax()
            .Select("SelectAjaxEditing", "myController")
            .Insert("InsertAjaxEditing", "myController")
            .Update("SaveAjaxEditing", "myController")
            .Delete("DeleteAjaxEditing", "myController");
    })       
    .Columns(columns => {            
        columns.Bound(o => o.Name).Width(200);            
        columns.Bound(o => o.Description).Width(400);
        columns.Command(commands => {
            commands.Edit();
            commands.Delete();
        }).Width(200);  
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("AjaxIndex", "myController"))
    .Editable(editing => editing.Mode(GridEditMode.InLine))               
    .Sortable()
    .Scrollable(h => h.Height("700px"))       
    .Groupable()        
    .Filterable()
) 

So if anyone knows why the rebind fails? Or if it is attributable to something else, please let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏天碎花小短裙 2024-12-29 06:44:19

事实证明,这是与工具相关的问题之一,而不是与实质内容相关的问题。当您删除此方法中的所有断点并让代码运行时,它会按预期工作。不知何故,在调试模式下设置断点时,它会抛出错误并停止应用程序。

AS it turns out this is one of those issues related to the tools and not the substance. When you remove all the breakpoints in this method and just let the code run it works as expected. Somehow, when in debugging mode, with breakpoints set, it throws an error an halts the application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文