Reputation: 10448
i want to add a hyperlink in my message like
ModelState.AddModelError("_FORM", "Please report this error <a href="asdf.aspx">Click Here</a>");
Im using asp.net mvc 2. How can i do this?
Upvotes: 3
Views: 1034
Reputation: 2775
The problem is that the ValidationMessage
and ValidationSummary
methods internally use the SetInnerText() method which automatically encodes the values you have saved in the Model Errors.
Like queen3 suggests, you'll have to write your own versions of these methods to overcome this.
You can see original methods in the MVC2 source code here.
Replace tagNameHere.SetInnerText(value)
with tagNameHere.InnerHtml = value
Important Note: Please make sure you take great care with where the information displayed in these messages comes from, you're allowing html now, so you're susceptible to Cross Site Scripting
Upvotes: 1