How can I insert HTML tags in C# string property?

asp.net-mvc-3, c#

Solution

There's nothing fundamentally wrong with doing that but it probably won't render the way you're expecting.

You can use `@Html.Raw` as others have suggested, but I think it's better to explicitly declare your model in such a way as to indicate that it may contain html. You probably want to use the `MvcHtmlString` class for this instead:

public MvcHtmlString TextNotIncluded 
{ 
    get { return MvcHtmlString.Create("which is <u>not</u> included in the Quote"); }
}

Then in your view you can just use:

@Model.TextNotIncluded

Problem

Not sure how if it is possible, but I have this in a class: ``` public string TextNotIncluded { get { return ("which is <u>not</u> included in the Quote"); } } ``` The `<u>` and `</u>` are being displayed in my view, rather than the word not being underlined. I am not familiar with C#. Can anyone provide a quick answer? Thanks. Edit: I am just calling this in my view thusly: `@MyClass.TextNotIncluded`. Wrapping it with `@Html.Raw` is not efficient in my case because I have this sprinkled throughout dozens of views.

Original source