3

I have my model with:

[RequiredIfTrue("OtherField", ErrorMessage = "The field {0} cannot be blank")]
[Display(Name = "The Name")]
public string Name { get; set; }

I set the ErrorMessage then I was expecting that, in validation, the error message was "The field The Name cannot be blank", but I'm getting "The The Name field is required.".

Did I miss something? Why I'm getting the default message?

PS: I don't know if makes any difference but I'm using server side validation (ModelState).

UPDATE

In the same model I have Required (Native from .Net) being used, and Required works well. But all RequiredIf doesn't.

Jonny Piazzi
  • 3,684
  • 4
  • 34
  • 81
  • Code looks correct. Are you sure you have the latest bits deployed? Also, you might consider wrapping the field name in single quotes or square brackets for readability: `"The field '{0}' cannot be blank"` – Rufus L Sep 16 '14 at 23:47
  • I'm update all foolproof dlls but still don't working. – Jonny Piazzi Sep 17 '14 at 14:34
  • Any resolution to this? I'm having the same issue. It behaves the same for me on client-side validation so it's not just server-side. – RichC Jul 16 '15 at 17:43
  • Looks like I've narrowed it down to my custom EditorFor fields. "Out of the box" EditorFor fields show the expected ErrorMessage but for my custom EditorTemplates, it uses the default MVC ErrorMessage and ignores the FoolProof defined ErrorMessage. – RichC Jul 16 '15 at 18:23

0 Answers0