Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Wouldn't that display a substring the namespace and type of FirstName? Commented Apr 14, 2020 at 11:25
  • 2
    This can break. DisplayFor() for a string by default returns an HtmlString, with the HTML-encoded string, but can also trigger a display template to be rendered, not all strings are rendered as plain strings. If the template returns more than the string, for example <span class="fancy-string">@Model</span>", or if the input string contains HTML entities ("foo&amp;bar"), you now have partial HTML being printed. Using a separate model property that returns a substring is the way to go.
    – CodeCaster
    Commented Nov 19, 2020 at 8:00