1

I have a role based @html.ActionLink() .Which show or hide link based on user permission.ASP.NET MVC5 Default @html.ActionLink() works fine.

But i want to pass angularjs value as a route value.

  @Html.ActionLink("Edit", "Edit", "Branches", new { id = "{{branch.BranchId}}" })

but this code render following code

<a href="/Branches/Edit?Length=8" id="22">Edit</a>

i found this link but can't find a solution. @Html.ActionLink and Angularjs value? I want to pass angularjs value using actionLink() not Url.Action()

Thanks

3
  • try this @Html.ActionLink("Edit", "Edit", "Branches", new { id = "{{branch.BranchId}}" },null) Commented Dec 14, 2017 at 12:05
  • yes already tried this . not working :( . Commented Dec 14, 2017 at 12:55
  • this won't work. the Html.ActionLink is rendered server side, while Angularjs is rendered client side. At the time the ActionLink is created, the information from the expression would not be available. Commented Dec 14, 2017 at 14:02

1 Answer 1

1

This could work for you. Just remove the controller name from the parameters.

@Html.ActionLink("Edit", "Edit", new { id = "{{branch.BranchId}}" })

Or like this with controller name

@Html.ActionLink("Edit", "Edit", "Branches", new { id = "{{branch.BranchId}}" }, null)

Or you can try this

@{
     var link = Url.Action("Edit", "Branches", new { id = "{{branch.BranchId}}" });
     link = HttpUtility.UrlDecode(link);
 }
 <a href="@link">Edit</a>
Sign up to request clarification or add additional context in comments.

2 Comments

sorry not working .both generate this . <a href="/Branches/Edit/%7B%7Bbranch.BranchId%7D%7D">Edit</a>
It seems like there is some issue in binding from AngularJS expression {{branch.BranchId}} here.

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.