r.r r.r - 2 months ago 9
Javascript Question

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

Answer

To redirect:

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