Following is my Model for Product
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
}
And following is my View code
<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();
}
Other than the Name
property, validation isn't working.