resx 文件中的 Razor 语法
Razor syntax inside resx file
我在视图中有以下剃须刀语法:
(@Html.ActionLink(SQPStrings.ForgotPassword, "ResetPassword", "User", new { Area = "Authentication" }, new { }))
在 resx 文件中我有以下文本:
Password: use your password (case sensitive) (insert the actionlink here)
我似乎找不到如何进行此操作,有人可以帮助我找到正确的方向吗?我知道我需要在视图中执行 String.Format
并添加参数,但具体方法不详。
您可以在 resx 文件的字符串值中为 string.Format
定义占位符:
Password: use your password (case sensitive) ({0})
然后在 Razor 视图中将该值格式化为翻译后的字符串。
使用 Html.Raw
渲染结果字符串,否则其中包含的 <a href=".."\>
将被转义。
var actionLink = Html.ActionLink("Link name" , "ResetPassword", "User", new { Area = "Authentication" }, new { }));
var resetDisplay = string.Format(SQPStrings.ForgotPassword, actionLink);
@Html.Raw(resetDisplay)
您可以通过将 "insert the actionlink here" 部分替换为占位符 {0} 来更改 .resx 文件中的文本,如下所示:
<data name="ForgotPassword" xml:space="preserve">
<value>Password: use your password (case sensitive) ({0})</value>
</data>
在视图中,您应该像这样将 string.Format()
与 Html.Row()
助手结合使用:
@Html.Raw(string.Format(SQPStrings.ForgotPassword, Html.ActionLink(link, "ResetPassword", "User", new { Area = "Authentication" }, new { }))))
其中 link
是您 link 的字符串名称。
我在视图中有以下剃须刀语法:
(@Html.ActionLink(SQPStrings.ForgotPassword, "ResetPassword", "User", new { Area = "Authentication" }, new { }))
在 resx 文件中我有以下文本:
Password: use your password (case sensitive) (insert the actionlink here)
我似乎找不到如何进行此操作,有人可以帮助我找到正确的方向吗?我知道我需要在视图中执行 String.Format
并添加参数,但具体方法不详。
您可以在 resx 文件的字符串值中为 string.Format
定义占位符:
Password: use your password (case sensitive) ({0})
然后在 Razor 视图中将该值格式化为翻译后的字符串。
使用 Html.Raw
渲染结果字符串,否则其中包含的 <a href=".."\>
将被转义。
var actionLink = Html.ActionLink("Link name" , "ResetPassword", "User", new { Area = "Authentication" }, new { }));
var resetDisplay = string.Format(SQPStrings.ForgotPassword, actionLink);
@Html.Raw(resetDisplay)
您可以通过将 "insert the actionlink here" 部分替换为占位符 {0} 来更改 .resx 文件中的文本,如下所示:
<data name="ForgotPassword" xml:space="preserve">
<value>Password: use your password (case sensitive) ({0})</value>
</data>
在视图中,您应该像这样将 string.Format()
与 Html.Row()
助手结合使用:
@Html.Raw(string.Format(SQPStrings.ForgotPassword, Html.ActionLink(link, "ResetPassword", "User", new { Area = "Authentication" }, new { }))))
其中 link
是您 link 的字符串名称。