2

How can we pass angularjs expression/ varibale to asp.net mvc actionlink ?

Here is my asp.net mvc actionlink code

 @Html.ActionLink("{{row.x}}", "Details", "Info", new { id = "{{row.x}}" }, null)

In the first parameter {{row.x}} works fine as it displays value but when being passed as route parameter it retains itself as {{row.x}} and does not evaulate.If i remove quotes it doesnt compile.

2 Answers 2

6

Razor code executes at the server. So you cannot pass your client side angular variable as the route value dictionary parameter for the Html.ActionLink helper method.

What you can do is build the html markup for the link with pure html and append angular data in the href value as needed. You can still use Url.Action helper method to build the correct relative url to the Info action method.

<a href="@Url.Action("Info","Details")?id={{row.x}}">{{row.x}}</a>
Sign up to request clarification or add additional context in comments.

Comments

2

You can use ng-href and Url.Content as following

<a ng-href="@Url.Content("~/Info/Details/")?id={{row.x}}">{{row.x}}</a>

Comments

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.