RedirectToAction with Ajax.Beginform , unexpected results

前端 未结 2 1584
粉色の甜心
粉色の甜心 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;
    }
    

提交回复
热议问题