Javascript 第二次打开时,Modal会变成黑色屏幕

Javascript 第二次打开时,Modal会变成黑色屏幕,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我已经编写了一个编辑模式,它确实有效,但是当我关闭该模式并尝试再次打开它时,它就变暗了 我的链接调用modal @Html.ActionLink("Editar", "GetEditSv", "Sv", new { id = sv.IDServico },new{data_target = "#modal-container", data_toggle = "modal"}) 父视图中的我的容器 <div id="modal-container" class="modal fade hi

我已经编写了一个编辑模式,它确实有效,但是当我关闭该模式并尝试再次打开它时,它就变暗了

我的链接调用modal

@Html.ActionLink("Editar", "GetEditSv", "Sv", new { id = sv.IDServico },new{data_target = "#modal-container", data_toggle = "modal"})
父视图中的我的容器

<div id="modal-container" class="modal fade hidden-print" tabindex="-1" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">

    </div>
</div>
试试这个,使用
$('body').find('modal-background').removeClass('modal-background')
删除
背景
效果(暗背景)


$(函数(){
//当模式关闭时
$('#modal container').on('hidden.bs.modal',function(){
//从中删除bs.modal数据属性
$(this.removeData('bs.modal');
//并清空模态内容元素
$('#modal container.modal content').empty();
//移除背景
$('modal-container').find('modal-background').removeClass('modal-background');
});
});
$(“#模态容器”).on('show.bs.modal',函数(事件){
var按钮=$(event.relatedTarget);
var url=button.attr(“href”);
var modal=$(本);
//请注意,每次打开modal时,这将替换modal contant的内容
modal.find('.modal content').load(url);
});
试试这个,使用
$('body').find('modal-background').removeClass('modal-background')
删除
背景
效果(暗背景)


$(函数(){
//当模式关闭时
$('#modal container').on('hidden.bs.modal',function(){
//从中删除bs.modal数据属性
$(this.removeData('bs.modal');
//并清空模态内容元素
$('#modal container.modal content').empty();
//移除背景
$('modal-container').find('modal-background').removeClass('modal-background');
});
});
$(“#模态容器”).on('show.bs.modal',函数(事件){
var按钮=$(event.relatedTarget);
var url=button.attr(“href”);
var modal=$(本);
//请注意,每次打开modal时,这将替换modal contant的内容
modal.find('.modal content').load(url);
});

您如何关闭您的modal?试着像
$('#modal container').modal('close')这是
模态背景
类未正确删除(模态未正确关闭)@maheshinghchoushan它不起作用你如何关闭模态?试着像
$('#modal container').modal('close')这是
模态背景
类未正确删除(模态未正确关闭)@MaheshSinghChouhan它不好用,现在第二次只出现一秒钟,然后消失。在那之后,我的父视图中的其他下拉列表不再起作用。我必须重新刷新我的页面。@FabricyoFigueira除非我看到你的渲染代码(html、js等),否则很难调试。你是如何关闭模式的?默认情况下,它应该删除
背景
。可以尝试
$('modal-container')。查找('modal-background')。删除类('modal-background')否。。。这只是让问题回到过去。你想看看我的全部代码吗?@FabricyoFigueira只是想了解你是如何关闭模式的?似乎它没有正确关闭。是的,经过一次关闭后:
如果我再尝试使用一次,它就不再工作了。很好,现在第二次只出现一秒钟,然后消失。在那之后,我的父视图中的其他下拉列表不再起作用。我必须重新刷新我的页面。@FabricyoFigueira除非我看到你的渲染代码(html、js等),否则很难调试。你是如何关闭模式的?默认情况下,它应该删除
背景
。可以尝试
$('modal-container')。查找('modal-background')。删除类('modal-background')否。。。这只是让问题回到过去。你想看看我的全部代码吗?@FabricyoFigueira只是想了解你是如何关闭模式的?似乎它没有正确关闭。是的,经过一次关闭后:
如果我再尝试使用一次,它就不再工作了。
<script>
   $(function () {
              //when the modal is closed
              $('#modal-container').on('hidden.bs.modal', function () {
                  //remove the bs.modal data attribute from it
                  $(this).removeData('bs.modal');
                  //and empty the modal-content element
                  $('#modal-container .modal-content').empty();
              });
          });
    $('#modal-container').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var url = button.attr("href");
        var modal = $(this);

        //note that this will replace the content of modal-contant ever time the modal is opened
        modal.find('.modal-content').load(url);
    });
</script>
@model ControleIntegrado.Models.Servico


@using (Html.BeginForm("EditSv", "Sv", FormMethod.Post))
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Servico</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.IDServico)

        <div class="form-group">
            @Html.LabelFor(model => model.Data, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Data.Date, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Data, "", new { @class = "text-danger" })
            </div>
        </div> 
       <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Salvar" class="btn btn-default" />
                <input type="button" class="btn btn-default" data-dismiss="modal" value="cancelar"/>
            </div>
        </div>
    </div>
}
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/jquery-ui-1.12.1.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
public ActionResult GetEditSv(int id)
    {
        using(DBControle db = new DBControle())
        {
            foreach (var item in db.Servico)
            {
                if(item.IDServico == id)
                {
                    return PartialView("GetEditSv", item);
                }
            }
        }
        return ViewBag();
    }
<script>
   $(function () {
              //when the modal is closed
              $('#modal-container').on('hidden.bs.modal', function () {
                  //remove the bs.modal data attribute from it
                  $(this).removeData('bs.modal');
                  //and empty the modal-content element
                  $('#modal-container .modal-content').empty();

                  //remove backdrop
                   $('#modal-container').find('.modal-backdrop').removeClass('modal-backdrop');
              });
          });
    $('#modal-container').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var url = button.attr("href");
        var modal = $(this);

        //note that this will replace the content of modal-contant ever time the modal is opened
        modal.find('.modal-content').load(url);
    });
</script>