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();
}
その他の私のビューのコードです動作していません。
いいですね。あなたは質問がありましたか? –
LOL ...はい私は持っていたので、他のバリデーション(名前を除く)が動作しない理由がありました。 ShortDescriptionまたは長い説明に何も入力せずに保存をクリックすると、非妥当性検証メッセージが表示されず、フォームがポストバックされます –