Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Troubles with jquery ui dialog and save method
Message
 
 
To
03/04/2013 12:34:00
General information
Forum:
ASP.NET
Category:
MVC
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01569821
Message ID:
01569924
Views:
15
>You may not THINK the validation rules are violated, but they ARE. Figure out which one and fix it.

That's the thing - this is why I added the else case - I see in that else case that the error message is about Ext. And this is strange, as my Ext is defined here
[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).

I am going to try commenting out the [StringLength(5)] just to see if it will now became Valid.


>
>>This is my Edit method to update data:
>>
>>[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);
>>            }
>>        }
>>
>>So the problem now that IsValid returns false although I don't believe I break any rules. All I do is to add some address and then I click on Save button. The save has the following code:
>>
>>
>> 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');
>>
>>So, why IsValid returns false and seems to be pointing to the Ext method validation, I have no idea :(
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform