【问题标题】:Bootstrap Modal with model ASP.NET MVC 4带有模型 ASP.NET MVC 4 的引导模式
【发布时间】:2017-08-22 15:26:17
【问题描述】:

我在 .Net MVC 4 和 Bootstrap 中有一个 webapp。我需要用模型中的一些数据显示一个模态。我的页面是用模型输入的。问题是这样的: 如果我将模态 div 放在我的页面中(此页面使用布局),则 div 作为模态对话框打开,但看起来变暗并且无法单击。如果我将模态 div 放在主布局中,模态看起来还可以,但是我不能在模态 div 内使用模型,因为我的布局不是模型类型的。一种选择是对我的布局进行建模,另一种选择可能将我的 div 保留在我的页面中,但使用一些将我的模态 div 放在所有前面的属性(如 z-index)。我尝试了最后一个,但没有成功。

我页面中的代码。

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<div id="myModal" class="modal fade" role="dialog" style="z-index: 150;">
    <div class="modal-dialog" style="z-index: 151;">
        <div class="modal-content" style="z-index: 152;">
            <div class="modal-header" style="z-index: 153;">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body" style="z-index: 153;">
                <label>Hello @Model.UserName</label>
            </div>
            <div class="modal-footer" style="z-index: 153;">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

    标签: asp.net-mvc bootstrap-modal


    【解决方案1】:

    尝试使用引导页面中示例中的那个。我经常使用它们而没有问题。

    `<div class="modal fade">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <p>Modal body text goes here.</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-primary">Save changes</button>
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          </div>
        </div>
      </div>
    </div>`
    

    【讨论】:

      【解决方案2】:

      只需从&lt;div&gt; 中删除style 属性,即idmyModal(至少只是第一期)。

      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
      <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
      
      
      <div id="myModal" class="modal fade" role="dialog" style="z-index: 150;">
          <div class="modal-dialog" style="z-index: 151;">
              <div class="modal-content" style="z-index: 152;">
                  <div class="modal-header" style="z-index: 153;">
                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                      <h4 class="modal-title">Modal Header</h4>
                  </div>
                  <div class="modal-body" style="z-index: 153;">
                      <label>Hello @Model.UserName</label>
                  </div>
                  <div class="modal-footer" style="z-index: 153;">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                  </div>
              </div>
          </div>
      </div>
      <div id="myModal2" class="modal fade" role="dialog">
          <div class="modal-dialog">
              <div class="modal-content">
                  <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal">&times;</button>
                      <h4 class="modal-title">Modal Header</h4>
                  </div>
                  <div class="modal-body">
                      <label>Hello @Model.UserName</label>
                  </div>
                  <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                  </div>
              </div>
          </div>
      </div>
      <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal2">Open Modal without Style attribute</button>
      <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal with Style attribute</button>

      【讨论】:

        【解决方案3】:

        我通过使用将 div 保留在我的页面中(未移动到布局) 我的 div 模式中的属性 data-backdrop="false"。有了这个, 模态看起来不错。

        我从所有 div 中删除了所有 z-index 属性。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-29
          • 1970-01-01
          • 1970-01-01
          • 2018-09-27
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多