Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Webgrid选择行而不使用SelectLink_C#_Asp.net Mvc 4_Razor - Fatal编程技术网

C# Webgrid选择行而不使用SelectLink

C# Webgrid选择行而不使用SelectLink,c#,asp.net-mvc-4,razor,C#,Asp.net Mvc 4,Razor,我用的是MVC4和Razor 在我的cshtml文件中,我有一个Webgrid。如何在不使用selectLink、复选框或单选按钮的情况下选择行 我在这里试图实现的场景是- 在Webgrid中显示包含数据的列,然后在不使用selectLink或类似操作的情况下选择一行。并基于此选择,将此值发送到控制器 至于到目前为止我尝试了什么。。。 我一直在关注下面这些链接中的教程- 这两个例子都很好,但都使用SelectLink方法。有人能举个例子吗?不用WebGrid自己的功能,只要使用一些jQuery

我用的是MVC4和Razor

在我的cshtml文件中,我有一个Webgrid。如何在不使用selectLink、复选框或单选按钮的情况下选择行

我在这里试图实现的场景是-

在Webgrid中显示包含数据的列,然后在不使用selectLink或类似操作的情况下选择一行。并基于此选择,将此值发送到控制器

至于到目前为止我尝试了什么。。。 我一直在关注下面这些链接中的教程-


这两个例子都很好,但都使用SelectLink方法。有人能举个例子吗?

不用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 */)

    });

});

那么您希望如何选择该行?通过点击行本身,或者?嘿,谢谢你的回复。我对JQuery有点陌生。你能解释一下这部分的意思和作用吗$('table>body>tr')我知道一旦用户在行内单击,就会调用click函数。我不明白这个('table>body>tr')。。。再次感谢。我真的很感激。这一块叫做jQuery选择器,它们基本上遵循CSS选择器的规则。语法
$(table>tbody>tr)
从所选元素创建jQuery对象,在本例中,所有
tr
元素都是
body
元素的子元素,而这些子元素又是
table
元素的子元素。