Redirect a URL from JavaScript to a controller in MVC with Angular

0

I have declared the following in angular.js

.when('/plan', {
      templateUrl: 'Main/LinkTiless',
    controller: 'PlanCtrl',
    controllerAs: 'planEstudios'

I will not send it to a view as it is typically done, Content\Views\PlanEstudios but I want to send it to a controller.

Note: As a test on my controller I try to redirect it to the google page in the following way.

 public ActionResult LinkTiles()
 {            
      return Redirect("https://www.google.com");
 }

Problem: By clicking on the Curriculum icon, do not go anywhere, do not take any action.

Beforehand, thanks for the help.

    
asked by Drz 09.12.2016 в 17:20
source

1 answer

3

It seems that you have some quibbles with the concepts. You can not send it to a view, you must send it to an action of a controller.

I guess you have a Controller called Main something like this:

public class MainController : Controller
{
    public ActionResult LinkTiles()
    {
         return Redirect("https://www.google.com");
    } 
}

In the beginning, your JavaScript code sends the wrong action because it has an extra "s", in the second it checks if you can access it directly from the browser.

In case you do not want to move from Angular you can do redirect with

window.location = "@Url.Action("LinkTiles","Main")";
    
answered by 09.12.2016 в 17:35