Telerik MVC 网格重新绑定崩溃
按照 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()));
}
一切都可以达到返回行,所以我尝试了:
- return View(new GridModel(myTypeRepository.All);
- return View(new GridModel(myTypeRepository.All.ToList());
- return视图(新的GridModel(myTypeRepository.All.ToArray());
- 返回视图(新的GridModel(myTypeRepository.All);
- 返回视图(新GridModel(myTypeRepository.All.ToList());
- 返回视图(new GridModel(myTypeRepository.All.ToArray());
- 返回视图(GridModel(myTypeRepository.All))
- 返回视图(GridModel(myTypeRepository.All.ToList()))
- 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:
- return View(new GridModel(myTypeRepository.All);
- return View(new GridModel(myTypeRepository.All.ToList());
- return View(new GridModel(myTypeRepository.All.ToArray());
- return View(new GridModel(myTypeRepository.All);
- return View(new GridModel(myTypeRepository.All.ToList());
- return View(new GridModel(myTypeRepository.All.ToArray());
- return View(GridModel(myTypeRepository.All))
- return View(GridModel(myTypeRepository.All.ToList()))
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实证明,这是与工具相关的问题之一,而不是与实质内容相关的问题。当您删除此方法中的所有断点并让代码运行时,它会按预期工作。不知何故,在调试模式下设置断点时,它会抛出错误并停止应用程序。
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.