MVC 3 Data Annotation Attributes ignored intermittently
I've extended DataAnnotationExtensions project with support for Min/Max/RangeWords validations, both server- and client-side. Validations work beautifully, but I'm seeing the following problem:
Given a field in the model described as
[Required(ErrorMessage = "Please enter a short description")]
[MaxWords(40, ErrorMessage = "Description is too long - 40 words max")]
[DisplayName("Business description")]
[DataType(DataType.MultilineText)]
public string Description { get; set; }
Data.MultilineText only has effect immediately after I recompile the project (and/or make some changes that require recompile). After that, multi-line class doesn't get added to the field in question. In other words: the first time I run the form, everything looks fine; on the second run, the attribute is apparently ignored, and I'm getting a single-line text box.
I should point out that in the project开发者_如何学编程, error messages and descriptions are not in English, but in Hebrew (not sure if that has any effect). Additionally, validation works, both inside this project and in a separate test project.
What could be the culprit? Is it something on my side, or a bug in DataType processing?
Thanks and regards, Ilya.
You should use text area in you view if you can.
@Html.TextAreaFor(model => model.Description)
You could also write EditorTemplate for this, implement the html that you want and use the @Html.EditorFor(model => model.Description)
Hope this helps
精彩评论