Search code examples
c#razorresx

Razor syntax inside resx file


I have the following razor syntax inside the view:

(@Html.ActionLink(SQPStrings.ForgotPassword, "ResetPassword", "User", new { Area = "Authentication" }, new { }))

In the resx file I have the following text:

Password: use your password (case sensitive) (insert the actionlink here)

I cannot seem to find how to proceed with this, can someone help me get in the right direction? I know I need to do a String.Format in the view and add the parameters but not excactly how.


Solution

  • You can define placeholders for string.Format in the string value of the resx file:

    Password: use your password (case sensitive) ({0})

    and then format the value into the translated string in the Razor view. Render the resulting string with Html.Raw or the <a href=".."\> contained in it will be escaped.

    var actionLink = Html.ActionLink("Link name" , "ResetPassword", "User", new { Area = "Authentication" }, new { }));
    var resetDisplay = string.Format(SQPStrings.ForgotPassword, actionLink);
    @Html.Raw(resetDisplay)