RedirectToAction with Ajax.Beginform , unexpected results

前端 未结 2 1581
粉色の甜心
粉色の甜心 2020-12-11 04:14

I have the following view , which contains an Ajax.BeginForm:-

@using (Ajax.BeginForm(\"ChangeDevicesSwitch\", \"Switch\", new AjaxOptions

{
    InsertionMo         


        
相关标签:
2条回答
  • 2020-12-11 04:38

    Return the url you want to make a redirect to from the action method when the operation succeeded:

    public ActionResult ChangeDevicesSwitch(SwitchJoin s)
    {
        try
        {
            ...
            return Json(new { RedirectUrl = Url.Action("Details", new { id = s.GeneralSwitchTo }) });
        }
        ...
    }
    

    And in the createsuccess:

    function createsuccess(data) {
        if (data.RedirectUrl)
            window.location.href = data.RedirectUrl;
    }
    
    0 讨论(0)
  • 2020-12-11 04:48

    in my case, following method was worked

    function OnSuccess(data) {
        var json;
            if (data.responseText instanceof Object)
                json = data.responseText;
            else
                json = $.parseJSON(data.responseText);
    
            if (json.RedirectUrl)
                window.location.href = json.RedirectUrl;
    }
    
    0 讨论(0)
提交回复
热议问题