ASP.NET MVC - 添加到XHTML验证错误信息 [英] ASP.NET MVC - Add XHTML into validation error messages
问题描述
刚开始与ASP.Net MVC和已经打了一下关于确认消息的障碍的。
我已经指派给我的类自定义验证属性在我的模型验证几个属性。
Just starting with ASP.Net MVC and have hit a bit of a snag regarding validation messages. I've a custom validation attribute assigned to my class validate several properties on my model.
在此验证失败,我们希望该错误信息包含XHTML标记起来,包括链接,以帮助,(这是在原来的WebForms项目作为ASP实现:面板)。
When this validation fails, we'd like the error message to contain XHTML mark-up, including a link to help page, (this was done in the original WebForms project as a ASP:Panel).
目前的时刻XHTML标记诸如&下;一>,在的ErrorMessage被渲染到屏幕上。有没有什么办法让在ValidationSummary正确呈现XHTML标记?还是有更好的方式来处理这种验证?
At the moment the XHTML tags such as "< a >", in the ErrorMessage are being rendered to the screen. Is there any way to get the ValidationSummary to render the XHTML markup correctly? Or is there a better way to handle this kind of validation?
感谢
推荐答案
OK,感谢tvanfosson关于查看源$ C $ c中的建议。
OK, thanks to tvanfosson for the suggestion about looking at the source code.
我本质上推出未HtmlEn code在ModelState中的任何错误信息,只是推迟到innerHTML的我自己Html.ValidationSummaryXHTML帮手
I essentially rolled my own "Html.ValidationSummaryXHTML" helper that didn't HtmlEncode any error message in ModelState, just deferred to "InnerHtml".
作品一种享受!
这篇关于ASP.NET MVC - 添加到XHTML验证错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!