1

I want to use Html.ValidationSummary() but I have a hidden property that I don't want to show if it is invalid. Because IsTrue is set on it I get the validation message, if I set the ErrorMessage to simply have a space, the validation will still render as a list element with an empty space, which is to be expected.

Anyway I can do this without writing a custom validation?

Edit for code and clarification:

    [IsTrue]
    public bool Slug { get; set; }

And in the view:

@Html.ValidationSummary()

In the view if the property is not true I will still get an error message in the validation summary which I'd expect:

The field Slug is invalid.

However for this property I don't want it to render a validation message, but just for this property.

Edit for reason why I want this, as it is weird:

I have a requirement for this particular model validation to fail when Model.IsValid is called and the property is set to false but to not alert the user of any validation error. This is strange, I know, but all I need is for Model.IsValid to return false if the property is not set to true.

4

0 回答 0