除了使用 WebGrid 自己的功能之外,您还可以使用一些 jQuery 在单击行中的任意位置时触发行选择,如下所示:
$(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 */)
});
});