I am trying to encode this simple attribute...
var url = Url.Action("Method", new { code = "{{item.code}}" });
<a ng-href="@url">link</a>
I need the angular template delimiters output by the MVC framework intact.
The only thing that seems to work is this:
@Html.Raw("/a/b/c/d/{{item.code}}")
The problem with this approach is that I loose all the utility gained from Url.Action
. I want to make use of the routing where possible.
There should be a way to encode {{item.code}}
so that it is not transformed.
I've similar problem w jsView. That is how it works for me. Extension method:
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));
}
Usage:
<a href="@Html.RawLink(Url.Action("Action", "Controller", new { id = "{{:Id}}" }))">Some link</a>
or:
<a href="@Html.RawActionLink("Action", "Controller", new { id = "{{:Id}}" })">Some link</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.