Webgrid在不使用SelectLink的情况下选择行
本文关键字:情况下 选择 SelectLink Webgrid | 更新日期: 2023-09-27 18:28:57
我正在使用MVC4&剃须刀
在我的cshtml文件中,我有一个Webgrid。如何在不使用selectLink或复选框或单选按钮的情况下选择行?
我试图在这里实现的场景是-
在Webgrid中显示包含数据的列,然后选择一行而不使用selectLink或类似的内容。根据此选择,将此值发送到控制器。
至于到目前为止我已经尝试了什么。。。我一直在下面的链接中学习教程-示例1示例2
这两个例子都很好,但都使用SelectLink方法。有人能举个例子吗?
当他们点击行中的任何位置时,您可以使用一些jQuery来触发行选择,而不是使用WebGrid自己的功能,如下所示:
$(function () {
// this selector should target the WebGrid table, with an id or class that is
// set on the table
$('table > body > tr').click(function () {
// this will depend on how you action and routes are set up but this will
// work for the default route of "{controller}/{action}/{id}"
// also this will simply redirect to the URL with the selected row value,
// if your intention is to stay on the page consider using jQuery's ajax
// methods (i.e. .load(), $.get(), $.post() or $.ajax())
$(location).attr('href', @Url.Action("YourAction", "YourController") + '/' + /* get row value */)
});
});