Aistis Taraskevicius Aistis Taraskevicius - 4 months ago 43x
AngularJS Question

How to call/return mvc view from angular or with angular defined variable/s

$scope.showDetails = function (dashboard_item) {
url: '/Details/Details',
method: 'GET',
data: { name: dashboard_item.FName }

This will call method, but won't pass name to it and will return to angular controller. Instead of opening/staying on new page.

*onclick="location.href='@Url.Action("Details", "Details", new {name = $scope.dashboard_item.Fname })'"

This will properly open/return new page/view, but it can't access angular variable in razor/server side.

There doesn't seem to be any good examples or any information how to do something as simple as this.
I know I should be probably be using angular routes, but I've got no clue how and honestly I would rather stick with asp MVC routing, but anything at this point would do..

TLDR I want to return/call/open new MVC view while passing parameters to it


You can use something like this:

<a ng-href="@Url.Action("Details","Details")?name={{dashboard_item.Fname}}">Link</a>

in your razor view where you are using this angular controller.


To use it on all the elements, not only the anchor, you can create this function in your angular controller:

$scope.go = function ( path ) {
  $window.location.href = path;

and then on your view you can use something like this:

<tr ng-click="go('@Url.Action("CompanyProfileDetails","User")?name=' + profile.Name)">
  *another code here*