繁体   English   中英

在ASP.NET MVC中编码角度模板

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM