Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render span element with text from Model

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?

like image 740
NealR Avatar asked Sep 05 '25 03:09

NealR


1 Answers

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>
like image 68
Cloud SME Avatar answered Sep 07 '25 19:09

Cloud SME