jquery - 如何在 MVC 中使用动态数据填充模态弹出窗口内的下拉列表?

标签 jquery asp.net-mvc

我想用 MVC 中的动态数据填充模态弹出窗口内的下拉列表。当我单击 Open 时,DisplayModal 模式应在 dropdowmlist 中显示更新的数据。我的 Jquery 代码未显示下拉列表中包含新数据的模态弹出窗口。

查看

     <table>
       <tr>
           <td>
              @Html.DisplayName("IT")
             </td>
             <td>
      <a class="LinkId" data-toggle="modal"  data-url="/Home/_ModalPopup?Page=1">Open</a>
        </td>
           </tr>
              <tr>
               <td>
                 @Html.DisplayName("Sales")
                   </td>
                    <td>
        <a class="LinkId" data-toggle="modal"  data-url="/Home/_ModalPopup?Page=2">Open</a>

                  </td>
                </tr>                            
        </table>
    @{Html.RenderAction("__MEmpModal"); }

部分模态

<div class="modal fade" id="DisplayModal" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="form-group">
                    @Html.DropDownListFor(m => m.Category, Model.CategoriesList, new { @class = "form-control" })
                </div>               
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary pull-right">Save</button>
            </div>
        </div>
    </div>
</div>

脚本

 $(document).on("click", '.LinkId', function (e) {
        debugger;
        $.ajax({
            url: $(this).data("url"),
            type: "GET",
        }).done(function (partialViewResult) {
            $("#DisplayModal").html(partialViewResult);
            $('#DisplayModal').focus();
        });
    });

最佳答案

试试这个。

链接

<a href="/Home/_ModalPopup?Page=1" class="modal-link"> Open</a>

脚本

$('body').on('click', '.modal-link', function (e) {
        $('#modal-container').removeData('bs.modal');
        e.preventDefault();
        $(this).attr('data-target', '#modal-container');
        $(this).attr('data-toggle', 'modal');
        var url = $(this).attr('href');
        $.get(url, function (data) {
            $('#modal-content').html(data);
            $('#modal-container').modal('show');
        });


    });

关于jquery - 如何在 MVC 中使用动态数据填充模态弹出窗口内的下拉列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51604726/

相关文章:

javascript - jQuery "drop"和 "over"未在可放置对象上触发

asp.net-mvc - 允许使用 MVC 3 加号登录 URL

javascript - 如何在javascript上用回车键模拟tab键

javascript - 如何向 DIV 添加点击属性而不将其应用于其中的元素?

Javascript:在 <br> 之前和之后向内容添加元素

jquery - 不使用图像的 DIV 上的圆 Angular

c# - 有没有办法重用数据注释?

javascript - 根据用户在 HTML MVC 中的点击更改 Url.Content

c# - 由于 MySql,.NET MVC4 应用程序无法运行

asp.net-mvc - "' Sys ' is undefined"在 IIS7 中运行 ASP.NET MVC 应用程序时出错