Asp.net mvc TextAreaFor does not receive confirmation as a required field

I have a data entry field where I collect notes. A note data item is required for each note. Here is my model:

public interface INoteDataEntryViewModel : IMobilePageDataContract
{
    int CourseId { get; set; }

    [Required(ErrorMessage = @"Note is required")]
    String Note { get; set; }

    [DisplayName(@"Note Date")]
    DateTime NoteDate { get; set; }
}

You can see that I have the Required attribute for the Note property.

I use Razor to display a data entry form element:

<div data-role="fieldcontain">
    @Html.LabelFor(m => m.Note)
    @Html.TextAreaFor(m => m.Note)
    @Html.ValidationMessageFor(m => m.Note)
</div>

When I use "@ Html.TextAreaFor", there is no confirmation for the required field, and I can submit the form. However, if I go to "@ Html.TextBoxFor", then the validation is done for the required field and I cannot submit the form. Any ideas on why validation fails for TextAreaFor? I use unobtrusive ajax and am jQueryMobile.

Thank you for your help.

+5
source
1

Html.TextAreaFor(), [DataType(DataType.MultilineText)]. Html.EditorFor() Html.TextAreaFor() .

:

public interface INoteDataEntryViewModel : IMobilePageDataContract
{
    int CourseId { get; set; }

    [Required(ErrorMessage = @"Note is required")]
    [DataType(DataType.MultilineText)]
    String Note { get; set; }

    [DisplayName(@"Note Date")]       
    DateTime NoteDate { get; set; }
}

:

<div data-role="fieldcontain">
    @Html.LabelFor(m => m.Note)
    @Html.EditorFor(m => m.Note)
    @Html.ValidationMessageFor(m => m.Note)
</div>
+7

All Articles