FrenkyB FrenkyB - 3 months ago 8
CSS Question

DIV content not parsed as HTML

I am using VS2015, C#, MVC project.

I've created a custom calendar. When typing the note, it's correctly shown to the user as html (breaks, bold, italic ... - everything works fine).
If I try to update calendar (each DIVs content gets pulled from database) then DIVs content is no longer displayed as html but as plain text.

Why is that so?

I am parsing DIVs content with this code (@noteCurrentDate is DIVs content):

<div id="divDays" class="divDays">


@{
DateTime startDate = Convert.ToDateTime(Model.StartEndDateTable[0]["StartDate"]).Date;
DateTime endDate = Convert.ToDateTime(Model.StartEndDateTable[0]["EndDate"]).Date;

DateTime tempDate = startDate;

while (tempDate <= endDate)
{
DL.DataSets.Notes.spSelectNotesRow result = Model.NotesTable.AsEnumerable().Where(myRow => myRow.DateNote.Date == tempDate).FirstOrDefault();
string noteCurrentDate = "";
string activeDate = tempDate.Date.Month == Model.CurrentMonth ? "" : "dayUnactive";
string dateID = tempDate.Date.Day.ToString("d2") + "_" + tempDate.Date.Month.ToString("d2") + "_" + tempDate.Date.Year;

if (result != null)
{
noteCurrentDate = result.Note;
}

<div class="divDay">
<div class="divInnerDay">
<span id="spanDayNumber" class="spanDayNumber unselectable @activeDate">@tempDate.Date.Day</span>
<div id="@dateID" class="content editable" ng-keyup="updateNote('@dateID')">@noteCurrentDate</div>
</div>
</div>

tempDate = tempDate.AddDays(1);
}
}
</div>
<!-- divDays -->


When typing into field the content is shown like this:

enter image description here

Content is being saved on each key-up event to database:

<b>Text in bold</b><div><i>text in italic (one break before)</i></div><div><i><u>text underline (another break)</u></i></div>


So, html is correctly saved in database. But, when the page is refreshed, DIVs content is shown like this:

enter image description here

And here's the source. For me, it looks correct html. Why it is not parsed as html but as plain text?

enter image description here

Answer

Use @Html.Raw() for your content