$scope.showDetails = function (dashboard_item) {
    $log.debug("clicked");
    $http({
        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

share
    
I would highly prefer solution that doesn't use href as I need to make table column clickable as link, both currently posted involve a href and doesnt work with onclick – Aistis Taraskevicius Jun 15 '16 at 14:54
up vote 3 down vote accepted

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.

UPDATE

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*
</tr>
share
    
Got a solution that doesnt use href, need to have an object clickable not just a link? – Aistis Taraskevicius Jun 15 '16 at 14:55
    
@AistisTaraskevicius, but the anchor is also clickable :) so did you find the solution with button? or should I write the example with the button? – Markiyan Harbych Jun 15 '16 at 14:57
    
I need it for table row, so button wont do much good either probably – Aistis Taraskevicius Jun 15 '16 at 15:00
    
@AistisTaraskevicius, please check the update of the answer. – Markiyan Harbych Jun 15 '16 at 15:14
    
cheers it works, I've tried similar approach where I've tried to create link in angular and use angular path for it, but that got no where – Aistis Taraskevicius Jun 15 '16 at 15:21

As the razor executes in server side pass new object from client side is not possible but you can do pass as url params

<a href="@Url.Action("Details","Details")?name={{dashboard_item.Fname}}">Your link here </a>
share
    
doesn't work at least with angular throws error and variable stays as variable name, not its value onclick="location.href='@Url.Action("Details", "Details")?name={{dashboard_item.Fname}})'" as I need to make object clickable I cant use href, shouldn't make much difference – Aistis Taraskevicius Jun 15 '16 at 14:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.