so for pagination I have this url that when a user press the link it goes to the next page (the link parts are in a partial view), for that to work i get the dropdowbox value with javascript and pass to the url
@Html.ActionLink("|Siguiente >", "Index", new { pagina = Model.PageNumber + 1, ordenacion = ViewBag.Ordenacion, filtro = ViewBag.Filtro , empresa = "param-empresa" }, new { id = "mylinkSig" })
<script type="text/javascript">
$(function () {
$('#mylinkSig').click(function () {
var empresa = $("#empresa").val();
this.href = this.href.replace("param-empresa", encodeURIComponent(empresa));
});
});
</script>
as I use the script in almost all my page i want to put this script in a js file so i dont have to write it in all my view (pages) y try to copy/paste and put in a js file and it dont work (yes i have the .js file refence in my page)
so iam new to javascript so i dont know if i have to change the function for it could work in the .js file an use it in all my page
edit:
my Helper.js
$(function () {
$('#mylinkSig').click(function () {
var empresa = $("#empresa").val();
this.href = this.href.replace("param-empresa", encodeURIComponent(empresa));
});
});
function deleteConfirmation(response, status, data) {
// remove the row from the table
var rowId = "#widget-id-" + response.id;
$('.widgets').find(rowId).remove();
// display a status message with highlight
$('#actionMessage').text(response.message);
$('#actionMessage').effect("highlight", {}, 3000);
if (response.message == null) {
alert('No se pudo eliminar el registro');
}
else {
alert(response.message);
}
}
my view
<script src="@Url.Content("~/Scripts/Helper.js")" type="text/javascript"></script>
@*navigation << < >>>*@
<div>
Pagina @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
de @Model.PageCount
@if (Model.HasPreviousPage)
{
@Html.ActionLink("<<|", "Index", new { pagina = 1, ordenacion = ViewBag.Ordenacion, filtro = ViewBag.Filtro, empresa = "param-empresa" }, new { id = "mylinkFirst" })
@Html.Raw(" ");
@Html.ActionLink("< Anterior|", "Index", new { pagina = Model.PageNumber - 1, ordenacion = ViewBag.Ordenacion, filtro = ViewBag.Filtro, empresa = "param-empresa" }, new { id = "mylinkAnt" })
}
@if (Model.HasNextPage)
{
@Html.ActionLink("|Siguiente >", "Index", new { pagina = Model.PageNumber + 1, ordenacion = ViewBag.Ordenacion, filtro = ViewBag.Filtro , empresa = "param-empresa" }, new { id = "mylinkSig" })
@Html.Raw(" ");
@Html.ActionLink("|>>", "Index", new { pagina = Model.PageCount, ordenacion = ViewBag.Ordenacion, filtro = ViewBag.Filtro , empresa = "param-empresa"}, new { id = "mylinkLast" })
}
</div>
<script>tags though). What you may find is that you may need to attach it to the onLoad event of the body to make sure the page has loaded before it executes (depending on what you need to do).