我有一页“我们”的网页,我有一份问答清单。
public List<string> Questions = new List<string>()
{
"What browser are you using?",
"What version of the browser are you using?",
"And so on and so forth..."
};
public List<string> Answers { get; set; }
接着,我也认为:
@foreach (var question in Model.Questions)
{
<dt>
<dd width="240" height="25">@Html.Label(question)</dd>
<dd width="240" height="80">
@Html.ValidationMessageFor(model => model.Answers[Model.Index])
@Html.TextAreaFor(model => model.Answers[Model.Index], new { @class = "uniform", @id = "text" })
</dd>
</dt>
Model.Index += 1;
}
Before I go about writing a custom validator, is there a way I can validate each string in that list of answers similar to the way I would validate a string field?:
[StringLength(100)]
预告!