Skip to content
Advertisement

How to redirect to action from JavaScript method?

I have an input type=”button”

<input type="button" name="DeleteJob" runat="server" value="Löschen" onclick="DeleteJob()" />

and JavaScript method:

function DeleteJob() {

    if (confirm("Do you really want to delete selected job/s?"))
        return true;
    else
        return false;
}

How can I instead return true, redirect to Action DeleteJob?

[HttpGet]
public ActionResult DeleteJob(string selectedObject)
{
    return View();
}

Advertisement

Answer

To redirect:

function DeleteJob() {
    if (confirm("Do you really want to delete selected job/s?"))
        window.location.href = "your/url";
    else
        return false;
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement