Javascript ASP.NET MVC JQuery最接近val的HiddenFor

Javascript ASP.NET MVC JQuery最接近val的HiddenFor,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我有一张桌子: <table class="table table-bordered"> @for (var i = 0; i < Model.Count; i++) { <tr> <td width="25px"> @if (!Model[i].Letter.Equals(letter))

我有一张桌子:

  <table class="table table-bordered">
        @for (var i = 0; i < Model.Count; i++)
        {
            <tr>
                <td width="25px">
                    @if (!Model[i].Letter.Equals(letter))
                    {
                        @Html.DisplayTextFor(m => Model[i].Letter);

                    }
                </td>
                <td width="45px">
                    <div class="button-edit"></div>

                </td>
                <td>
                    @Html.HiddenFor(m => Model[i].Student.Id, new { @class = "mojaklasa" } )

                </td>

                <td>
                    ...
                </td>
                <td>
                  ...
                </td>
                <td>
                   ...
                </td>
            </tr>

        }
    </table>
还有这个,下一个。。。。 但是,如果我点击这个按钮,我在警报框中没有任何东西。
我甚至把类放在里面,但我可以从中得到这个文本

您需要找到父tr,然后尝试查找输入

$(document).ready(function () {
        $('.button-edit').each(function () {
            $(this).mouseenter(function () {
                $(this).fadeTo(20, 1).css('cursor', 'pointer');
            });
            $(this).mouseleave(function () {
                $(this).fadeTo(20, 0.5);
            });
            $(this).click(function () {
                var id;
                $(this).closest("tr").find('.mojaklasa').val(id);
                alert(id);

            });
        });
试试这个

$(this).closest('tr').find('.mojaklasa').val(id);

您需要相对于所单击项目的父项进行搜索,但决不应在每个事件中连接多个事件。这是毫无意义的,因为jQuery为您管理多个处理程序

$(function () {
    $('.button-edit').mouseenter(function () {
        $(this).fadeTo(20, 1).css('cursor', 'pointer');
    }).mouseleave(function () {
        $(this).fadeTo(20, 0.5);
    }).click(function () {
        var id = $(this).closest("tr").find('.mojaklasa').val();
        alert(id);
    });
});
这将把3个处理程序连接到class.button edit的所有元素。您还需要使用从val返回的值,而不是使用设置隐藏值的参数调用val

$(function () {
    $('.button-edit').mouseenter(function () {
        $(this).fadeTo(20, 1).css('cursor', 'pointer');
    }).mouseleave(function () {
        $(this).fadeTo(20, 0.5);
    }).click(function () {
        var id = $(this).closest("tr").find('.mojaklasa').val();
        alert(id);
    });
});