views:

500

answers:

2

In my scenario I'd like to display a text with URL link within validation message attached to form element on MVC view. I'm using ValidationExtensions.ValidationMessage extension method, like this:

<%=Html.ValidationMessage(Model.Name) %>

The behavior I'm seeing is that validation message is HTML escaped, what effectively prevents me from adding a link to message. Is there a way to circumvent this behavior? My error messages aren't user-supplied, so I don't think I have to worry about output sanitization here...

+3  A: 

I'm guessing that since Html.ValidationMessage is built in you're going to either create your own version, or if you're feeling creative, since it returns a string, assign that and then unescape the characters you want to change back.

string validation = Html.ValidationMessage(Model.Name);
validation = Regex.Replace(validation, "&gt;", "<");
//etc...
Hugoware
Thanks. I've created an 'UnEscape()' extension method for string - and now I can use it whenever I need.
Michał Chaniewski
A: 

You could use the HttpUtility.HtmlDecode(...) method along with your Html.ValidationMessage(...) method to get 'err done :D

Ravenclawmage