[ComplexType] public class PhoneInfo { [DataType(DataType.PhoneNumber)] [DisplayName("Phone")] [RegularExpression(@"^((\(\d{3}\)|\d{3})\s?)?\d{3}[-\s]?\d{4}\s*$", ErrorMessage = "Please enter valid Phone Number")] public virtual string Phone { get; set; } [StringLength(5)] [DisplayName("Ext")] public virtual string Ext { get; set; } public bool HasValue { get { return (Phone != null || Ext != null); } } }And I don't touch this field at all (which is empty).
>>[HttpPost] >> public ActionResult Edit(ClientViewModel model, FormCollection collection, Int32 id=0) >> { >> try >> { >> if (ModelState.IsValid) >> { >> Db.UpdateClient(model.Client); >> >> return this.Client(collection); >> } >> else >> foreach (ModelState state in ViewData.ModelState.Values.Where(x => x.Errors.Count > 0)) >> { >> var err = state; >> } >> return View(model); >> } >> catch >> { >> return View(model); >> } >> }>>
>> Save: function () { >> >> if ($("#add-edit-form").valid()) { >> >> var urlLoc = '/Client/Edit/' + currentId; >> if ($('#fntype').val() === "Add") >> urlLoc = '/Client/Add'; >> >> var form = $('form', this); >> debugger; >> var oForm = form.serialize(); >> oForm = oForm.concat($('#frmClientsSearch').serialize()); >> >> $.ajax({ >> type: 'POST', >> url: urlLoc, >> data: oForm, >> dataType: 'json', >> >> cache: false, >> //contentType: 'application/json', >> success: function (result) { >> debugger; >> $('#flexClients').flexAddData(result); >> } >> }); >> $(this).dialog('close');>>