ValidateInputAttribute不包含“排除"的定义 [英] ValidateInputAttribute does not contain a definition for Exclude

查看:54
本文介绍了ValidateInputAttribute不包含“排除"的定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC 3,并且试图在创建操作中从验证中排除某些字段.

I'm using MVC 3, and I'm trying to exclude some fields from validation in a create action.

我看到几个示例,这些示例显示了如何使用[ValidateInput(true,Exclude ="xxxx")]排除字段,但是当我尝试执行此操作时,出现此错误:

I see several examples showing how to exclude fields using [ValidateInput(true, Exclude = "xxxx")], but when I try this, I get this error:

"ValidateInputAttribute不包含排除的定义"

"ValidateInputAttribute does not contain a definition for Exclude"

有什么想法吗?

我有一个看起来像这样的局部类:

I have a partial class that looks like this:

[MetadataType(typeof(Article_Validation))]
public partial class article
{

}

public class Article_Validation
{
    [HiddenInput(DisplayValue = false)]
    public int article_id { get; set; }

    [Required(ErrorMessage = "Title is required")]
    public string article_title { get; set; }

    [AllowHtml]
    [Required(ErrorMessage = "Body is required")]
    public string article_body { get; set; }

    [HiddenInput(DisplayValue = false)]
    public DateTime article_datecreared { get; set; }

    [HiddenInput(DisplayValue = false)]
    public DateTime article_datemodified { get; set; }

    [HiddenInput(DisplayValue = false)]
    public int article_viewcount { get; set; }

    [AllowHtml]
    [Required(ErrorMessage = "Abstract is required")]
    public string article_abstract { get; set; }

}

[AllowHtml]放置在两个属性上,但是仍然出现错误.我的印象是,该类将与同名的EF类合并"?

The [AllowHtml] is placed on two properties, but I still get the error. I was under the impressionthat this class would be "merged" with the EF class of the same name?

如果我将[ValidateInput(false)]放在控制器上,它将正常工作.

If I put [ValidateInput(false)] on the controller, it works fine.

推荐答案

我最终将[ValidateInput(false)]放在用于创建和更新的操作方法上,以使html能够通过.也许不是首选的解决方案,但目前可以使用.

I ended up putting [ValidateInput(false)] on the action methods for create and update, in order for the html to pass through. Maybe not the preferred solution, but it works for now.

这篇关于ValidateInputAttribute不包含“排除"的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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