数据注解ErrorMessage属性使用HTML [英] Using html in ErrorMessage property of data annotations

查看:341
本文介绍了数据注解ErrorMessage属性使用HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道,如果它是可以做到以下几点:

Anyone know if it is possible to do the following:

public class User
{
    public Guid UserID { get; set; }

    [Required(ErrorMessage="A school selection is required.")]
    [Range(1, int.MaxValue, ErrorMessage="School not found.  Please contact support at <a href='mailto:support@mysite.com'>support@mysite.com</a>")]
    public int SchoolID { get; set; }

    // ... other properties
}

和没有 @ Html.ValidationMessageFor(型号=&GT; model.SchoolID)连接code中的HTML?也许我需要为这个自定义扩展帮手?是否有更简单的方法?任何指导,将AP preciated。如果一个辅助扩展是要走的路,我怎么能访问验证规则在辅助扩展方法,以确保HTML没有得到EN codeD?

And not have @Html.ValidationMessageFor(model => model.SchoolID) encode the HTML? Maybe I need to make a custom helper extension for this? Is there an easier way? Any guidance would be appreciated. If a helper extension is the way to go, how could I access the validation rules in the helper extension method to make sure the html doesn't get encoded?

感谢。

推荐答案

我做了一些更多的搜索和跨SO后下,解决怎么做,我问来了。我已经添加了这里的答案的情况下,任何人遇到这样的未来。我要纪念这个作为回答,以及因为它是最接近最佳答案我一直在寻找,但我会让版主决定,如果这需要停课时重复。

I did some more searching and came across the SO post below that addresses how to do what I am asking. I've added that answer here in case anyone comes across this in the future. I'm going to mark this as the answer as well since it is closest to the best answer I was looking for, but I'll let the moderators decide if this needs to be closed as a duplicate.

<一个href=\"http://stackoverflow.com/questions/8933853/render-html-tags-inside-of-html-validationmessagefor-in-mvc3\">Render里面HTML.ValidationMessageFor在MVC3 的HTML标签

这篇关于数据注解ErrorMessage属性使用HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆