@Html.ActionLink 和 Angularjs 值? [英] @Html.ActionLink and Angularjs value?
问题描述
嘿,我目前正在从事一个已经实现 angularjs 的项目,我想知道是否有办法在 Html Helper 中使用 angular 值?
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}} })
你如何使用 razor 语法中的值?
How do you use the value in razor syntax?
推荐答案
使用 ActionLink
的问题是该方法在创建 URL 时调用了 UrlPathEncode
.这意味着带有 get 编码的 razor 指令 {{}}
.Angular 将无法评估它.您需要做的是单独创建此 URL,然后对其进行解码.例如,我在我们项目的其中一个页面中有类似的内容.
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>
使用 ng-href
属性来设置 URL 非常重要.
It is very important that you use ng-href
attribute to set the URL.
这篇关于@Html.ActionLink 和 Angularjs 值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!