How to redirect to action from JavaScript method?

前端 未结 8 1940
孤城傲影
孤城傲影 2020-12-25 11:12

I have an input type=\"button\"


相关标签:
8条回答
  • 2020-12-25 12:12

    Use the @Url.Action method. This will work and determines the correct route regardless of what IIS server you deploy to.

    Example- window.location.href="@Url.Action("Action", "Controller")";

    so in the case of the Index action on the Home controller - window.location.href="@Url.Action("Index", "Home")";

    0 讨论(0)
  • 2020-12-25 12:17

    Maybe better to make an anchor with DeleteJob url instead of button?

    <a href="<%=Url.Action("DeleteJob", "YourController", new {selectedObject="someObject"})%>" onclick="return DeleteJob()">Löschen</a>
    

    and use your javascript you wrote already:

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

    So if function return true - you will be redirected. If function return false - you still stay on the page.

    0 讨论(0)
提交回复
热议问题