mercredi 23 décembre 2015

Why has Html.DisplayTextFor stopped showing the text as HTML?

I have an ASP.NET MVC3 web page which used to nicely display a C# string of HTML nicely. My server code programmatically loads the string with HTML tags for a nice table. The following cshtml has been showing this nice table as a nice table for years:

<h3>Nice Table:</h3>
@Html.DisplayTextFor( model => model.sNiceTable )

But today we notice browsers (Firefox & IE) are instead displaying it as a pile of text showing the HTML tag text:

<table><tr><th>...

rather than rendering it visually as a table, the way it did for years until now. The "Nice Table" header still displays properly.

Looking at the text in Firefox's developer Inspector shows HTML that looks like it should render as HTML, but (after showing the <h3> tag in color) it too has those tags from my string in black, even though when I paste the same string into an HTML file and load it, it shows the nice table. That is, Inspector shows the code as if it should work, but my string is in black for some reason that doesn't show in its code view.

Trying to use "view source" in Firefox or IE seems to be unusable for this, because the view part doesn't even show up there for some reason.

I see there are various other methods such as Display() and DisplayFor(), but they seem to do the same thing.

I haven't really touched this page since it last worked. The only thing I suspect that changed was applying some MS updates that had some other annoying side-effects on my projects.

What can I do to get this text to render again, rather than spew the HTML tags in the string as text?

Edit: model.sNiceTable is a C# string data member of the viewmodel, where the interface is:

public interface IMemberStatsViewModel
{
    string sNiceTable { get; set; }
    // other properties...
}

Its value gets assembled in my code which is called in the view model's constructor:

public MemberStatsViewModel()
    : base(new DataLayer.DataLayer(), ClientInterfaceTypeEnum.Web)
{
    InitializeMe();
}

InitializeMe() calls a data layer function which returns the C# string and assigns it to sNiceTable. The string is built based on stuff I look up in the data layer.

Aucun commentaire:

Enregistrer un commentaire