javascript - 在 Angular 中调用 $post 时如何使用 MVC 重定向

标签 javascript c# asp.net asp.net-mvc angularjs

所以,首先,我是 Angular 的新手,所以在将数据发送回服务器后,我对如何完成重定向感到有点迷失:

我的更新内容如下:

     $http.post("@Url.Action("SaveBranding", "AirlineConfig")", brandModel.model);

然后在服务器上我的 Controller 中有这个:

[HttpPost]
    public ActionResult SaveBranding(BrandingViewModel viewModel)
    {
        if (IsModelStateValid())
        {
            var airline = GetAirlineFromAirlinePlatformId(viewModel.AirlinePlatformId);

            switch (viewModel.PostAction)
            {
                case "Save":
                    BrandingViewModel.SaveEntity(viewModel, _db);
                    var airlineBranding = BrandingViewModel.FromEntity(_db.AirlinePlatforms.Single(x => x.AirlinePlatformId == viewModel.AirlinePlatformId).BrandingViews, viewModel.AirlinePlatformId);

                    return View("Branding", airlineBranding);
                case "Save & Close":
                    BrandingViewModel.SaveEntity(viewModel, _db);                     

                    return RedirectToAction("Edit", "AirlineConfig", new { id = airline.AirlineId });
                case "Cancel":
                    return RedirectToAction("Edit", "AirlineConfig", new { id = airline.AirlineId });
                default:
                    return HttpNotFound();
            }
        }
        return View("Branding"); //Replace this later
    }

我的路由不起作用,我不知道如何执行此操作,以便导航到正确的位置。

最佳答案

使用 window.location 在浏览器中手动重定向,而不是使用服务器重定向。

关于javascript - 在 Angular 中调用 $post 时如何使用 MVC 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28842591/

相关文章:

javascript - 与 Q.js 的 promise 作斗争

c# - 使用 javascript cookie 和 C# 抓取网站

javascript - 如何使用 Jquery 从另一个文本框和 radio 中的值更新 'total' 文本框

c# - 大量使用 Watin,IE 保持打开问题

javascript - 编译输出中的 TypeScript 依赖项未按正确顺序解析

javascript - 我怎样才能将这些功能安排为高阶

c# - Azure Function v2 中的 Microsoft.Azure.WebJobs.Host : Cannot bind parameter 'myContext' to type DataContext. 错误

asp.net - IIS/ASP/ASP.net : How to structure web-site to expose mobile version

javascript - 图表 js 标签和分组标签

c# - IMAP 搜索解析异常?