以下是我的产品型号
public class Product
{
public int Id { get; set; }
[Required(ErrorMessage = "Please Enter Product Name")]
[StringLength(100)]
public string Name { get; set; }
[Required(ErrorMessage = "Please Enter Short Desciption")]
[StringLength(200)]
. // other properties
. // Removed for brevity
}
以下是我的查看代码
<div class="contentHolder">
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
Html.Telerik().TabStrip()
.Name("TabStrip")
.Items(tabstrip =>
{
tabstrip.Add()
.Text("General")
.ContentHtmlAttributes(new { style = "height:700px" })
.Content(@<text>
<table>
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.Product.Name)
</td>
<td class="editor-field">
@Html.EditorFor(model => model.Product.Name)
@Html.ValidationMessageFor(model => model.Product.Name)
</td>
</tr>
<tr>
<td class="editor-label">
@Html.LabelFor(model => model.Product.ShortDescription)
</td>
<td class="editor-field">
@Html.TextAreaFor(model => model.Product.ShortDescription, new { cols = "50%", rows = "3" })
@Html.ValidationMessageFor(model => model.Product.ShortDescription)
</td>
</tr>
</table>
</text>);
})
.SelectedIndex(0)
.Render();
}
除Name
属性外,验证无效。
答案 0 :(得分:2)
我找到了问题的答案。这是Asp.net MVC 3中的错误或错误,因为它在此处报告:Unobtrusive Client Hooks Not Generated Via TextAreaFor For Nested Model Properties。这就是为什么我的案例中没有针对ShortDescription进行验证的原因,因为我使用的是@Html.TextAreaFor
。
希望在MVC4中删除它