E.Hamed E.Hamed - 1 month ago 9
jQuery Question

How to call a bootstrap modal which is in a partial?

I have that button which is

<li>
<a href="#" data-toggle="modal" data-target="#MyModal">
<span class="glyphicon glyphicon-log-in"></span> Login</a>
</li>


That
#MyModal
is inside a partial view
Login
that has its
ActionResult
in the controller . How to call that modal from within clicking on Login?

CSL CSL
Answer

Rather than data-attributes give your anchor element an id:

<a href="#" id='myanchor'>
     <span class="glyphicon glyphicon-log-in"></span> Login</a>

and then bind to the click event of that element in JavaScript:

  $('#myanchor').click(function(){
      $('#MyModal').modal('show'); 
  });