0
In my project I have a view
"Index" where I use the following script:
<script>$('#search').focus();</script>
Works normally on this view
"Index", but if within this view I have a table with some data where I have a button to edit and I click this button I will be redirected to a view
"Edit". And if I put this script inside this "Edit" it will not work.
Note: The same happens if I try to use a script in _Layout and within that layout have a Renderbody.
Edit1:
Short View 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 the one in the view that doesn’t work:
@model RamalAguia.Models.RamalModel
<head>
<title>asd</title>
</head>
<body>
//Edit
<script src="Scripts/jquery-2.1.0.js"></script>
</body>
Solved:
In my view _Layout
I was referencing jquery that way:
<script src="Content/bootstrap/dist/js/bootstrap.min.js"></script>
But when I switched this line to:
<script src="~/Content/bootstrap/dist/js/bootstrap.min.js"></script>
The scripts worked normally.
Do you have a Javascript error? In the views that don’t work, they have JQUERY? can post code?
– PauloHDSousa
No error, and have Jquery.
– Felipe Renan