3

Is there a way to render text into a span element when an ASP MVC 3 view loads? For instance if I have <span id="territoryName"></span> how would I load the data from Model.Region into the span element as text?

NealR
  • 9,361
  • 54
  • 153
  • 287

1 Answers1

3

If you are using Razor you can use the following.

<span id="territoryName">@Model.Region</span>

Note: the value will be HTML-encoded.

Without HTML-encoding:

<span id="territoryName">@Html.Raw(Model.Region)</span>
Cloud SME
  • 10,111
  • 3
  • 51
  • 90
  • The page really doesn't like the `Model.Region` part. With both I get the following error: `'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage.Model'` – NealR May 01 '13 at 17:52
  • 1
    See this - http://stackoverflow.com/questions/6204301/compiler-error-message-cs0135-model-conflicts-with-the-declaration-system-w – merekel May 01 '13 at 19:22
  • Used both the answer provided as well as the above question to solve this issue. Thanks! – NealR May 01 '13 at 20:06