2012-01-01 18 views
1

は、以下のために働くことは製品Asp.net検証がちょうど1つのプロパティ

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 
} 

のための私のモデルであり、次はNameプロパティ、検証より

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

その他の私のビューのコードです動作していません。

+0

いいですね。あなたは質問がありましたか? –

+0

LOL ...はい私は持っていたので、他のバリデーション(名前を除く)が動作しない理由がありました。 ShortDescriptionまたは長い説明に何も入力せずに保存をクリックすると、非妥当性検証メッセージが表示されず、フォームがポストバックされます –

答えて

2

私は私の問題の答えを見つけました。 Asp.net MVC 3のバグやエラーは、Unobtrusive Client Hooks Not Generated Via TextAreaFor For Nested Model Propertiesと報告されています。これは私が@Html.TextAreaForを使用しているので私のケースでShortDescriptionのバリデーションが起こっていない理由です。

MVC4でこれが削除されますようお願いいたします。

関連する問題