I have model with couple of regular expression on properties as below:
The view is dynamic view, that I am loading its content from jquery as below:
UPDATE: I found the issue but not the solution. The regular expression client side attributes are not rendered because I am using [UIHint("TextBox")] to add some custom classes and scripts. If I remove UIHInt, all validation attributes are generated without any issue. If I add UIHInt nothing generates.
Not sure what is wrong in my UIHInt editor template. pls advise???
EditorTemplate/TextBox.cshtml
@Html.TextBoxFor(m => Model, new {@class="txt"})
my model:
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; }
}
jquery unobtrusive is included in my bundles as:
bundles.Add(new ScriptBundle("~/js/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
View:
@model dynamic
@using (Html.BeginForm("Edit", null, FormMethod.Post, new { id="FrmIndex" }))
{
@Html.ValidationSummary(true);
@Html.EditorForModel()
<input type="submit" value="Edit" />
}
<script>
$(".datetime").datetime();
$(".combo").combo();
$(".chk").chk();
var form = $("#FrmIndex")
.removeData("validator") /* added by the raw jquery.validate plugin */
.removeData("unobtrusiveValidation"); /* added by the jquery unobtrusive plugin */
$.validator.unobtrusive.parse(form);
</script>
But still the the validations are not generated on client side. The message are generating from server side.
UPDATE: got some break through. These validations are working fine in my strongly typed views. However not in my dynamic view that I am currently showing here.
can somebody advise what is wrong I am doing here?