Hey i'm currently workin on a project that has implemented angularjs, i was wondering if there is a way around to use angular value in Html Helper?
This is what I can't get to work:
@Html.ActionLink("Edit", "Edit", new { id = {{row.Id}} })
How do you use the value in razor syntax?
Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.
Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.
ActionLink is rendered as an HTML Anchor Tag (HyperLink) and hence it produces a GET request to the Controller's Action method which cannot be used to send Model data (object). Hence in order to pass (send) Model data (object) from View to Controller using @Html.
@Html. ActionLink("name", "Action", "Controler", new { id= sentId, Style = "color:White" }, null);
The problem with using ActionLink
is that this method calls UrlPathEncode
when creating URL. What this means is that razor directive {{}}
with get encoded. Angular will not be able to evaluate it. What you will have to do is create this URL separately and then decode it. For example I have something like in one of the pages for our project.
@{
var url = Url.Action("Index", "Home", new{id="{{id=lastLatency}}"});
url = HttpUtility.UrlDecode(url);
}
<a data-ng-href="@url">Home</a>
It is very important that you use ng-href
attribute to set the URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With