I’m using MVC 3, and I’m trying to exclude some fields from validation in a create action.
I see several examples showing how to exclude fields using [ValidateInput(true, Exclude = “xxxx”)], but when I try this, I get this error:
“ValidateInputAttribute does not contain a definition for Exclude”
Any thougts?
Edit:
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; }
}
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?
If I put [ValidateInput(false)] on the controller, it works fine.
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.