my actual problem was here: Clinetside regular expression validation in MVC4
My model is:
public partial class PartyRole
{
[UIHint("TextBox")]
[RegularExpression(@"^.{5,}$", ErrorMessage="Minimum 5 characters required")]
[StringLength(50, ErrorMessage="Maximum {2} characters exceeded")]
public string Title { get; set; }
}
My uihint template (TextBox.cshtml)
@Html.TextBoxFor(m => Model, new {@class="txt"})
If I do not use UIHint, all the validation messages are rendered to client side. If I use UIHInt, not validation attributes for my regular expressions are generated on client side and validations are happening from server.
also, I have overriden the object.cshtml
@functions
{
bool ShouldShow (ModelMetadata metadata)
{
return metadata.ShowForEdit
&& metadata.ModelType != typeof(System.Data.EntityState)
&& !metadata.IsComplexType
&& !ViewData.TemplateInfo.Visited(metadata);
}
}
@if (ViewData.TemplateInfo.TemplateDepth > 1)
{
if (Model == null)
{
@ViewData.ModelMetadata.NullDisplayText
}
else
{
@ViewData.ModelMetadata.SimpleDisplayText
}
}
else
{
ViewData.Clear();
foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => ShouldShow(pm)))
{
if (prop.HideSurroundingHtml)
{
@Html.Editor(prop.PropertyName)
}
else if (prop.DisplayName == "Id")
{
<div></div>
}
else if (!string.IsNullOrEmpty(Html.Label(prop.PropertyName).ToHtmlString()))
{
<div class="editor-label">@Html.Label(prop.PropertyName)</div>
}
<div class="editor-field">@Html.Editor(prop.PropertyName) @Html.ValidationMessage(prop.PropertyName, "")</div>
}
}
Not sure if this causing any issue.
can somebody advise what am I doing wrong here?