1
    $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

1
  • 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 Commented Jun 15, 2016 at 14:54

2 Answers 2

5

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>
Sign up to request clarification or add additional context in comments.

5 Comments

Got a solution that doesnt use href, need to have an object clickable not just a link?
@AistisTaraskevicius, but the anchor is also clickable :) so did you find the solution with button? or should I write the example with the button?
I need it for table row, so button wont do much good either probably
@AistisTaraskevicius, please check the update of the answer.
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
0

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>

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.