JScripts work in one view but in others not!

0

In my project I have a view "Index" where I use the following script:          <script>$('#search').focus();</script>

It usually works on this view "Index", but if inside that view I have a table with some data where I have a button to edit and I click on this button I will be redirected to a view "Edit". And if I for this script within that "Edit" it will not work.

Note: The same happens if I try to use a script in _Layout and inside this layout have a RenderBody.

Edit1:

View summary code that works:

  @model IEnumerable<RamalAguia.Models.Usuario>
  <head>
     <title>Awsd</title>      
  </head>
  @{
     ViewBag.Title = "Index";
  }

  //Tabela

  <script src="Scripts/jquery-2.1.0.js"></script>
  <script type="text/javascript">
     var $rows = $('#ramaltable   tr');
     $('#search').keyup(function () {
        var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();

        $rows.show().filter(function () {
            var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
            return !~text.indexOf(val);
        }).hide();
  });
  </script>
  <script>
       $('#search').focus();
  </script>

And this is the view that does not work:

  @model RamalAguia.Models.RamalModel
 <head>
    <title>asd</title>
 </head>
 <body>

     //Edit

     <script src="Scripts/jquery-2.1.0.js"></script>

 </body>

Resolved:

In my view _Layout I was referencing jquery this way:

 <script src="Content/bootstrap/dist/js/bootstrap.min.js"></script>

But when I changed this line to:

<script src="~/Content/bootstrap/dist/js/bootstrap.min.js"></script>

The scripts worked normally.

    
asked by anonymous 21.07.2016 / 19:20

0 answers