I have an input type=\"button\"
function DeleteJob() {
if (confirm("Do you really want to delete selected job/s?"))
window.location.href = "/{controller}/{action}/{params}";
else
return false;
}
I struggled with this a little because I wanted to use Knockout to bind the button to the click event. Here's my button and the relevant function from inside my view model.
<a class="btn btn-secondary showBusy" data-bind="click: back">Back to Dashboard</a>
var vm = function () {
...
self.back = function() {
window.location.href = '@Url.Action("LicenseDashboard", "Application")';
}
}
I wish that I could just comment on yojimbo87's answer to post this, but I don't have enough reputation to comment yet. It was pointed out that this relative path only works from the root:
window.location.href = "/{controller}/{action}/{params}";
Just wanted to confirm that you can use @Url.Content to provide the absolute path:
function DeleteJob() {
if (confirm("Do you really want to delete selected job/s?"))
window.location.href = '@Url.Content("~/{controller}/{action}/{params}")';
else
return false;
}
(This is more of a comment but I can't comment because of the low reputation, somebody might find these useful)
If you're in sth.com/product and you want to redirect to sth.com/product/index use
window.location.href = "index";
If you want to redirect to sth.com/home
window.location.href = "/home";
and if you want you want to redirect to sth.com/home/index
window.location.href = "/home/index";
To redirect:
function DeleteJob() {
if (confirm("Do you really want to delete selected job/s?"))
window.location.href = "your/url";
else
return false;
}
Youcan either send a Ajax request to server or use window.location to that url.