Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render strings on a cshtml from a class with constants

I have a public class like this:

namespace MyProgram.Common
{
     public static class UIStrings
     {
          public const string Title = "Hellow World"
          public const string SubTitle = "This is another string. Please click on '<a href=\"/Home/Status\" target=\"_blank">Here</a>'"
     }
}

And then, on my Index.csthml I have the following code:

<label id="title" for="MyTitle">@Myprogram.Common.UiStrings.Title </label>
<label id="title" for="SubTitle">@Myprogram.Common.UiStrings.SubTitle </label>

The title renders fine but the link that I defined in the Subtitle doesn't render as a link but as the string itself.

Is there a way this can be done? I want to avoid to hardcode the strings in the cshtml file...

like image 840
user3587624 Avatar asked Oct 15 '25 03:10

user3587624


1 Answers

User Html.Raw

<label id="title" for="MyTitle">@Myprogram.Common.UiStrings.Title </label>
<label id="title" for="SubTitle">@Html.Raw(Myprogram.Common.UiStrings.SubTitle) </label>
like image 103
K D Avatar answered Oct 17 '25 23:10

K D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!