Jyina
Jyina

Reputation: 2902

How to redirect to an MVC view from AngularJS controller?

I need to redirect to another MVC view from a controller in AngularJS. Which services do I need to inject? I tried $window service and it does not work. Do I have to use $http service? Does anyone have any example for this? Thank you!

AngularJS controller:

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

MVC controller:

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

Upvotes: 1

Views: 2172

Answers (2)

Kiran Dodani
Kiran Dodani

Reputation: 101

You should try with full path in location

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

Upvotes: 3

Pankaj Parkar
Pankaj Parkar

Reputation: 136144

location is not an method over window object. Simply assign URL to location property

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

Upvotes: 3

Related Questions