Reputation: 9352
I use a tiny_mce plugin to have a textarea with advanced editing (bold, italic, ...) see below. The attribute behind this textarea is required (validation).
@Html.TextAreaFor(m => m.Project.Content, new { style = "height:250px;width:100%;", @class = "mceEditor" })
@Html.ValidationMessageFor(m => m.Project.Content)
In my model, I defined the attribute as required.
[Required]
public string Content { get; set; }
The problem is that when I submit my form for the first time, I have a validation error on this control (even if something is typed in it). The second time the form is submitted I don't have any validation error.
Any idea?
Thanks.
Upvotes: 0
Views: 88
Reputation: 13594
Well, It's basically a bug in Asp.net MVC3 due to which the unobtrusive validations don't work for nested properties in TextAreaFor. You can read further at codeplex workitem.
I would suggest you to use the Editorfor in it's place and decorate the respective property with following code :-
[DataType(DataType.MultilineText)]
[Required]
public string Content { get; set; }
Upvotes: 1