我有以下视图模型
public class QuestionarrieAnswersViewModel
{
public long QuestionID { get; set; }
public string Question { get; set; }
[Required(ErrorMessage="required")]
[StringLength(255, ErrorMessage = "Maximum 255 characters are allowed.")]
public string Answer { get; set; }
}
我正在以下方式生成视图
@model List<BusinessLayer.Models.ViewModel.QuestionarrieAnswersViewModel>
@using (Ajax.BeginForm("SaveQuestionarrie", "Member", FormMethod.Post, new AjaxOptions { OnBegin = "OnBegin", OnComplete = "OnComplete" }, new { @class = "form-horizontal" }))
{
for(int i=0;i<Model.Count;i++)
{
<div class="control-group">
<div class="head_form">
<label class="control-label">@Model[i].Question</label>
<div class="controls">
@Html.TextAreaFor(m=>m[i].Answer)
@Html.ValidationMessageFor(m => m[i].Answer)
@Html.HiddenFor(m=>m[i].QuestionID)
</div>
</div>
</div>
}
<div class="control-group">
<div class="controls">
<button class="btn" type="submit">Save</button>
</div>
</div>
}
我已经在上面模型中的 Answer 字段上设置了数据注释,但是如果我以下面的方式生成视图,它不会在上面的视图中应用
@model BusinessLayer.Models.ViewModel.QuestionarrieAnswersViewModel
@using (Ajax.BeginForm("SaveQuestionarrie", "Member", FormMethod.Post, new AjaxOptions { OnBegin = "OnBegin", OnComplete = "OnComplete" }, new { @class = "form-horizontal" }))
{
@Html.TextAreaFor(m => m.Answer)
@Html.TextAreaFor(m => m.QuestionID)
<div class="control-group">
<div class="controls">
<button class="btn" type="submit">Save</button>
</div>
</div>
}
这里出了什么问题...