笑故挽风 2017-06-26 02:42 采纳率: 100%
浏览 12

无法调用ajax函数

I created a view in MVC 5 with table like this:

@foreach (var item in Model)
{
    <tr>
        <td>
            <h3 class="label label-primary">@item.FRM_CODE</h3>
        </td>
        <td>
            @Html.DisplayFor(model => item.FRM_NAME)
        </td>
        <td>
            @Html.DisplayFor(model => item.FRM_DES)
        </td>
        <td>
            <input type="date" class="form-control" id="dateNgayPsinhDlieu" />
        </td>
        <td>
            <input type="button" id="btnCreatReport" class="btn btn-primary" value="@item.FRM_NAME" />
        </td>
    </tr>
}

<script>
 $('#btnCreatReport').bind("click", function () {
                var controller = $('#btnCreatReport').attr('value');
                homeController.printData(controller);
                 alert(controller);
               
            });

</script>

I just call function success the first button and the buttons next is not response the ajax function. Help me

</div>
  • 写回答

2条回答 默认 最新

  • 北城已荒凉 2017-06-26 07:34
    关注

    Try to put the button click event inside $(document).ready(function(){ }) and test once. Below is the Code.

    $(document).ready(function(){
         $('#btnCreatReport').bind("click", function () {
                    var controller = $('#btnCreatReport').attr('value');
                    homeController.printData(controller);
                     alert(controller);
    
         });
    });
    
    评论

报告相同问题?