【发布时间】:2012-01-01 07:47:25
【问题描述】:
以下是我的产品模型
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 属性,验证不起作用。
【问题讨论】:
-
很好。你有问题吗?
-
LOL...是的,我有,这就是为什么其他验证(名称除外)不起作用的原因。当我点击保存而不在 ShortDescription 或长描述中输入任何内容时,不会显示无干扰的验证消息,并且表单会发回
标签: c# asp.net-mvc-3 unobtrusive-validation