[英]encode angular template in ASP.NET mvc
我正在嘗試編碼這個簡單的屬性...
var url = Url.Action("Method", new { code = "{{item.code}}" });
<a ng-href="@url">link</a>
我需要完整的MVC框架輸出的角度模板定界符。
似乎唯一起作用的是:
@Html.Raw("/a/b/c/d/{{item.code}}")
這種方法的問題是,我失去了從Url.Action
獲得的所有實用程序。 我想盡可能利用路由。
應該有一種對{{item.code}}
進行編碼的方式,以便不進行轉換。
我有類似的問題w jsView。 這就是對我有效的方式。 擴展方式:
public static IHtmlString RawLink(this HtmlHelper helper, string link)
{
return helper.Raw(HttpUtility.UrlDecode(link));
}
public static IHtmlString RawActionLink(
this HtmlHelper helper,
string actionName,
string controllerName,
object routeValues)
{
var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
return RawLink(helper, urlHelper.Action(actionName, controllerName, routeValues));
}
用法:
<a href="@Html.RawLink(Url.Action("Action", "Controller", new { id = "{{:Id}}" }))">Some link</a>
要么:
<a href="@Html.RawActionLink("Action", "Controller", new { id = "{{:Id}}" })">Some link</a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.