title: MVC 5 Bootstrap Modal not working
body: <p>I’m still in the MVC learning mode and one of the things I need is a Delete Confirmation modal and I would like to use Bootstrap to do that. I’ve searched around and came up with some examples that I’ve looked over a few times but I can’t seem to get it to work.</p>
  
  <p>I made sure I had the latest version of Bootstap (v3.3.5) downloaded and in my Content folder. I know Bootstrap and the site can see it because the layout of my buttons and grid all seem to be styled correctly. </p>
  
  <p>However using the sample code below when I click on my “Test Modal” button it doesn’t open a modal. It just displays the partial view without any CSS/Bootstrap styling. Also the cancel button and save button inside the modal aren’t firing off any code. I’m curious if anyone sees what I’m doing wrong or has any suggestions on how I can figure out the issue. </p>
  
  <p>This is in the  section of my _Layout.cshtml page. </p>
  
  <pre><code>&lt;style&gt;
          .modal-content {
              width: 600px !important;
              margin: 30px auto !important;
          }
      &lt;/style&gt;
  
      &lt;script type="text/javascript"&gt;
          $(function () {
              // Initalize modal dialog
              // attach modal-container bootstrap attributes to links with .modal-link class.
              // when a link is clicked with these attributes, bootstrap will display the href content in a modal dialog.
              $('body').on('click', '.modal-link', function (e) {
                  e.preventDefault();
                  $(this).attr('data-target', '#modal-container');
                  $(this).attr('data-toggle', 'modal');
              });
  
              // Attach listener to .modal-close-btn's so that when the button is pressed the modal dialog disappears
              $('body').on('click', '.modal-close-btn', function () {
                  $('#modal-container').modal('hide');
              });
  
              //clear modal cache, so that new content can be loaded
              $('#modal-container').on('hidden.bs.modal', function () {
                  $(this).removeData('bs.modal');
              });
  
              $('#CancelModal').on('click', function () {
                  return false;
              });
          });
      &lt;/script&gt;
  </code></pre>
  
  <p>This is in the  section of my _Layout.cshtml page. </p>
  
  <pre><code>&lt;div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"&gt;
          &lt;div class="modal-dialog"&gt;
              &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header"&gt;
                      &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                      &lt;h4 class="modal-title" id="myModalLabel"&gt;Delete Example&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      Are you sure you wish to delete this item?
                  &lt;/div&gt;
                  &lt;div class="modal-footer"&gt;
                      &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
                      &lt;button type="button" id="mySubmit" class="btn btn-primary"&gt;Confirm&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>This is the link I’m using in my Index.cshtml page.</p>
  
  <pre><code>@Html.ActionLink("Test Modal ", "ViewSampleModal", "Admin", null, new { @class = "modal-link btn-xs btn-success" })
  </code></pre>
  
  <p>This is in my AdminController. </p>
  
  <pre><code>[HttpGet]
          public ActionResult ViewSampleModal()
          {
              return PartialView("_SampleModal");
          }
  [HttpPost]
      public ActionResult ModalClick()
      {
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>This is my _SampleModal.cshtml.</p>
  
  <pre><code>&lt;div class="modal-body"&gt;
      &lt;div class="alert alert-warning"&gt;
          &lt;span class="glyphicon glyphicon-warning-sign"&gt;&lt;/span&gt;
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec consequat nisl a nibh tincidunt condimentum. Nullam in augue vitae augue dictum eleifend. Nunc porta fermentum metus, quis efficitur lectus scelerisque ac. Quisque egestas sit amet nunc in interdum. Etiam malesuada maximus nisi, id tempus metus. Vivamus at sapien ut metus aliquet sodales sed id magna. Integer in auctor ex. Phasellus tempor, est vel placerat dapibus, nulla dui tempor ligula, at pulvinar libero nunc gravida metus. Proin non feugiat felis. Proin ut ultrices ex. Morbi aliquet lacinia elit at bibendum. Nunc facilisis, neque a finibus dignissim, turpis felis vulputate diam, a tristique tellus nibh nec nulla. Suspendisse eget augue non turpis dignissim euismod eget eget odio. Donec sit amet nibh cursus, efficitur nibh in, sodales arcu. Pellentesque pulvinar consequat lacus ac porttitor.
      &lt;/div&gt;
  
      @using (Html.BeginForm("ModalClick", "Admin", FormMethod.Post))
      {
          &lt;div class="row"&gt;
              &amp;nbsp;
          &lt;/div&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-4 col-md-offset-4"&gt;
                  &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Cancel&lt;/button&gt;
                  &lt;button type="submit" id="approve-btn" class="btn btn-danger"&gt;Save&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      }
  &lt;/div&gt;
  
  
  &lt;script type="text/javascript"&gt;
      $(function () {
          $('#approve-btn').click(function () {
              $('#modal-container').modal('hide');
          });
      });
  &lt;/script&gt;
  </code></pre>