I have a macro in which i'm building up a message from a few parameters on a node. However when i output it (using the variable that i built up containing all the HTML), it renders the encoded value, IE: I see the HTML on the page, not the rendered HTML.
Here's my code (a snippet of it anyway):
@if (showMessage)
{
//@(Html.Raw(message.ToString()));
@message;
}
@functions{
...
protected override void InitializePage()
{
...
var requestedUrl = Request.Url.PathAndQuery.ToString(); // default get back to same page after valid login;
if (isLoggedIn)
{
if (!isSubmitLogout)
{
message = String.Format("<div class=\"header\">{0}</div>", @Model.signedInConfirmationHeader);
message = String.Concat(message, String.Format("<p>{0}</p>", @Model.signedInConfirmationMessage)); //Html.Raw(@Model.signedInConfirmationMessage)
message = message.Replace("%USER%", currentUser.UserName);
try
{
message = Html.Raw(message);
}
catch (Exception ex)
{
message = String.Format("ERROR: {0}", ex.Message);
}
showMessage = true;
So in the above code, it errors. It doesn't even handle the exception and show the message, i just get a message saying there was an error with the script.
If i remove the Html.Raw(..) block, it'll work but not render the HTML.
I'm pretty stumped with this.. any ideas??
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/34717-struggling-with-htmlraw-macro-outputting-html-encoded-value