c# - How to escape html.actionLink tags in string.format -
c# - How to escape html.actionLink <a></a> tags in string.format -
to create url within translatable text utilize {0}
placeholder.
so do:
@string.format(@translationhelper.gettranslation("label-clicktocontinue"), @html.actionlink( @translationhelper.gettranslation("text-here"), "login", new { model.username, model.uniqueid } ) )
translation keys:
label-clicktocontinue = "click {0} continue" text-here = "here"
but prints escaped string source: <a href="/login/login?username=alberttest3&amp;uniqueid=f3647fed-bab4-4575-bb5f-98ed27edff43">label-requestnewofficewizard</a>
how create sure it'll not show html-tag, url?
this not supported actionlink helper. html encodes text. either write own custom helper doesn't encode text or simply:
<a href="@url.action(login, new { username, model.uniqueid })"> @html.raw(translationhelper.gettranslation("text-here")) </a>
by way have posted code looks ugly. go ahead , write custom helper:
public static class htmlextensions { public static ihtmlstring actionlinklocalized( htmlhelper html, string translationtext, string actionname, object routevalues ) { var urlhelper = new urlhelper(html.viewcontext.requestcontext); var anchor = new tagbuilder("a"); anchor.attributes["href"] = urlhelper.action(actionname, routevalues); anchor.innerhtml = translationhelper.gettranslation(translationtext); homecoming new htmlstring(anchor.tostring()); } }
and in view simply:
@html.actionlinklocalized("text-here", "login", new { username, model.uniqueid })
c# asp.net asp.net-mvc
Comments
Post a Comment