How to redirect to action from JavaScript method? How to redirect to action from JavaScript method? javascript javascript

How to redirect to action from JavaScript method?


To redirect:

function DeleteJob() {    if (confirm("Do you really want to delete selected job/s?"))        window.location.href = "your/url";    else        return false;}


function DeleteJob() {    if (confirm("Do you really want to delete selected job/s?"))        window.location.href = "/{controller}/{action}/{params}";    else        return false;}


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;}