【问题标题】:How to redirect to an MVC view from AngularJS controller?如何从 AngularJS 控制器重定向到 MVC 视图?
【发布时间】:2018-05-25 10:34:12
【问题描述】:

我需要从 AngularJS 中的控制器重定向到另一个 MVC 视图。我需要注入哪些服务?我试过 $window 服务 它不起作用。我必须使用 $http 服务吗? 有没有人有这方面的例子?谢谢!

AngularJS 控制器:

$window.location('/Home/Index');

MVC 控制器:

 public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }

【问题讨论】:

标签: angularjs asp.net-mvc angular-ui-router angularjs-controller


【解决方案1】:

location 不是window 对象的方法。只需将 URL 分配给位置 property

 $window.location = '/Home/Index';

【讨论】:

    【解决方案2】:

    您应该尝试使用位置中的完整路径

    var url = "http://" + $window.location.host + "/Home/Index";
    $window.location.href = url;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-20
      相关资源
      最近更新 更多