I created a Macro for my sites users to go in and create content cards. So they don't have to touch the code, I have locked down the code and only allowed them to put in pieces of content via the macro. One of these parts is the Google tracking code. When uploaded everything looks great except for the tracking code. Since there are special characters, it parses all of them out and turns something that is supposed to look like this:
So in your case the code would be @Html.Raw(HttpUtility.HtmlDecode(macroText));
I'm not sure whether you would need to add a namespace for being able to access "HttpUtility" though.
Also I'm not sure whether using @Html.Raw() is ever a good idea since it can be a potential security issue - But I'm no security expert so I'm not teaching a lesson here just mentioning that it's something to consider as well when going down this path :-)
Second...I'm wondering if allowing the editors / Giving the editors the responsibility of adding the tracking code is the best way to go? I realize that it it's perhaps a request from the client - But I'm wondering if you could perhaps make it a checkbox instead? So you have a boolean and if that boolean is true you could generate the tracking code on the fly? This of course again depends on your scenario and the logic behind the content creation but it might be worth considering.
Characters in macro text area
I created a Macro for my sites users to go in and create content cards. So they don't have to touch the code, I have locked down the code and only allowed them to put in pieces of content via the macro. One of these parts is the Google tracking code. When uploaded everything looks great except for the tracking code. Since there are special characters, it parses all of them out and turns something that is supposed to look like this:
to something that looks like this:
Obviously the tracking code doesnt work this way. I have tried the @Html.raw() method but that didn't see to work either:
Is there a way to allow pure html inside those macro Textareas?
Hi Mike
I'm not sure this is the best way of solving your issue but I saw this piece of code
@Html.Raw(HttpUtility.HtmlDecode(blog.Body));
from this post http://stackoverflow.com/questions/9556008/html-raw-is-not-working-asp-net-mvc on SO, which may solve your issue too?So in your case the code would be
@Html.Raw(HttpUtility.HtmlDecode(macroText))
; I'm not sure whether you would need to add a namespace for being able to access "HttpUtility" though.Also I'm not sure whether using @Html.Raw() is ever a good idea since it can be a potential security issue - But I'm no security expert so I'm not teaching a lesson here just mentioning that it's something to consider as well when going down this path :-)
Second...I'm wondering if allowing the editors / Giving the editors the responsibility of adding the tracking code is the best way to go? I realize that it it's perhaps a request from the client - But I'm wondering if you could perhaps make it a checkbox instead? So you have a boolean and if that boolean is true you could generate the tracking code on the fly? This of course again depends on your scenario and the logic behind the content creation but it might be worth considering.
Hope this helps a bit at least.
Cheers, Jan
is working on a reply...