0

MVC4とRazorを使用しています。

私の cshtml ファイルには Webgrid があります。selectLink、チェックボックス、またはラジオボタンを使用せずに行を選択するにはどうすればよいですか?

ここで達成しようとしているシナリオは -

Webgrid でデータを含む列を表示し、selectLink などを使用せずに 1 つの行を選択します。そして、この選択に基づいて、この値をコントローラーに送信します。

これまでに試したことについては...以下のリンクからチュートリアルに従っています- 例1 例2

どちらの例も優れていますが、どちらも SelectLink アプローチを使用しています。誰かが例を挙げることができますか?

4

1 に答える 1

0

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

    });

});
于 2013-08-24T17:25:04.757 に答える