1

I've taken the code from the bootstrap site to come up with the following function which needs to auto open a selected modal if the int: ModalId is not 0. In Vis studio there is a syntax error red line under the ')' before .modal, and in the chrome debugger it says 'uncaught type error, $(...).modal is not a function'. What am I doing wrong please?

$(document).ready(function() {
       if (@Model.ModalId != 0) {
           $('#accepted_'+@Model.ModalId).modal('show');
       }
    });
Jynn
  • 287
  • 1
  • 3
  • 18

2 Answers2

2

You have to add bootstrap.min.js in your index.html file.

Ranjith S
  • 205
  • 1
  • 5
1

As you can see here it is important to place the dependencies in the proper order.

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <script type="text/javascript">
     $(document).ready(function() {
       if (@Model.ModalId != 0) {
           $('#accepted_'+@Model.ModalId).modal('show');
       }
      });
    </script>

If this is not the case, plz add more code.

Community
  • 1
  • 1
cs04iz1
  • 1,737
  • 1
  • 17
  • 30
  • Great it's working thanks! I don't know how many times I've gone looking into complicated solutions to the problem when I've missed the obvious first step. Gotta stop doing that. Since the modal was already working I didn't think it was needing any extra script file references, but now I see modal('show') needed bootstrap.min.js. – Jynn Jun 26 '15 at 13:31
  • I had similar problems myself. We tent to search the improbable, when the simple thinks cause the problems.Glad i helped. If you want accept the answer :) – cs04iz1 Jun 26 '15 at 13:35