Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Html.ActionLink and Angularjs value?

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?

like image 229
ShaqCode Avatar asked Aug 07 '14 12:08

ShaqCode


People also ask

What is the use of HTML ActionLink?

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.

What is difference between HTML ActionLink and URL action?

Yes, there is a difference. Html. ActionLink generates an <a href=".."></a> tag whereas Url. Action returns only an url.

How do I transfer data from ActionLink to controller?

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.

How do I change the color of an ActionLink in HTML?

@Html. ActionLink("name", "Action", "Controler", new { id= sentId, Style = "color:White" }, null);


1 Answers

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.

like image 147
ByteBlocks Avatar answered Sep 28 '22 12:09

ByteBlocks