Have simple model with RegularExpression attribute. This attribute correct work with unobtrusive validation.
Render data in Grid.
On edit record in popup editor, have javascript error "SyntaxError: invalid quantifier" because in html field render parameter data-val-regex-pattern="+?d[ds-]+d". All backslashes is disappear.
ОК, write expression as @"\\+?\\d[\\d-]+\\d". Validation on page is OK, but in action method ModelState.IsValid = false. How can I solve this problem? Code of action method see below.
public class PersonModel{ public int PersonId { get; set; } [RegularExpression(@"\+?\d[\d-]+\d")] public string Phone { get; set; }}Render data in Grid.
@(Html.Kendo().Grid<PersonModel>().Name("Persons") .DataSource(src => src.Ajax() .Model(model => model.Id(p => p.PersonId)) .Read("_GetPersons", "Account") .Create("_CreatePerson", "Account") .Update("_UpdatePerson", "Account") .Destroy("_DestroyPerson", "Account") .ServerOperation(true) ) .ToolBar(command => command.Create()) .Columns(col => { col.Bound(p => p.PersonId).Hidden(); col.Bound(p => p.Phone); col.Command(command => { command.Edit(); command.Destroy(); }); }) .Pageable() .Editable(e => e.Mode(GridEditMode.PopUp)))On edit record in popup editor, have javascript error "SyntaxError: invalid quantifier" because in html field render parameter data-val-regex-pattern="+?d[ds-]+d". All backslashes is disappear.
ОК, write expression as @"\\+?\\d[\\d-]+\\d". Validation on page is OK, but in action method ModelState.IsValid = false. How can I solve this problem? Code of action method see below.
[HttpPost]public ActionResult _UpdatePerson([DataSourceRequest] DataSourceRequest request, PersonModel model){ if (model != null && ModelState.IsValid) { DB.UpdatePerson(model); } return new JsonNetResult { Data = ModelState.ToDataSourceResult() };}