C# Asp.net验证仅适用于一个属性

C# Asp.net验证仅适用于一个属性,c#,asp.net-mvc-3,unobtrusive-validation,C#,Asp.net Mvc 3,Unobtrusive Validation,下面是我的产品模型 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")]

下面是我的产品模型

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();
}

@使用(Html.BeginForm())
{
@Html.ValidationSummary(true)
Html.Telerik().TabStrip()
.名称(“TabStrip”)
.Items(tabstrip=>
{
tabstrip.Add()
.案文(“一般”)
.contentHtmlatAttributes(新的{style=“height:700px”})
.内容(@
@LabelFor(model=>model.Product.Name)
@EditorFor(model=>model.Product.Name)
@Html.ValidationMessageFor(model=>model.Product.Name)
@LabelFor(model=>model.Product.ShortDescription)
@Html.TextAreaFor(model=>model.Product.ShortDescription,新的{cols=“50%”,rows=“3”})
@Html.ValidationMessageFor(model=>model.Product.ShortDescription)
);
})
.已选择索引(0)
.Render();
}


除了
Name
属性之外,验证不起作用。

我找到了问题的答案。这是Asp.net MVC 3中的一个bug或错误,如下所述:。这就是为什么在我的例子中没有对ShortDescription进行验证的原因,因为我使用的是
@Html.TextAreaFor


希望这在MVC4中被删除,这很好。你有问题吗?哈哈…是的,我有,这就是为什么其他验证(除了名称)不起作用。当我单击save而不在ShortDescription或long description中输入任何内容时,不会显示非独占性验证消息,并且表单会被发回