Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Troubles with jquery ui dialog and save method
Message
From
03/04/2013 03:22:30
 
 
To
02/04/2013 22:23:44
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:
01569843
Views:
33
If no data was sent then wouldn't the routing fail ?

Maybe I should have looked more closely but seemed to me that the problem was exactly what the exception stated : there is no parameterless constructor for the model....

>No parameterless constructor would indicate nothing is being sent from jquery. Put in some Alert boxes to test for specific values.
>
>>Hi everybody,
>>
>>When I try to save data using jquery ui dialog I am getting the following error (few lines from the stack in FireBug console HTML):
>>
>>[MissingMethodException: No parameterless constructor defined for this object.]
>>   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
>>   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
>>   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
>>   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
>>   System.Activator.CreateInstance(Type type) +6
>>   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +183
>>   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +564
>>   System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +416
>>   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +317
>>   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +117
>>   System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +446
>>
>>I made some searches and I think it may be related to my model?
>>
>>The ViewModel is defined this way:
>>
>>
>>using System;
>>using System.Collections.Generic;
>>using System.Linq;
>>using System.Web;
>>using System.Web.Mvc;
>>using CardNumbers.Objects;
>>using System.ComponentModel.DataAnnotations;
>>using System.ComponentModel;
>>
>>using DataAnnotationsExtensions;
>>using System.ComponentModel.DataAnnotations.Schema;
>>
>>namespace CardNumbers.Models
>>{
>>    public class ClientViewModel
>>    {
>>        public Client Client { get; set; }
>>
>>        [Key]
>>        [Editable(false)]
>>        [Column("ClientId", TypeName = "int")]
>>        public virtual int? ClientId
>>        {
>>            get
>>            {
>>                if (Client == null)
>>                    return null;
>>                else
>>                    return Client.Id;
>>            }
>>
>>            set { Client.Id = value ?? 0; }
>>        }
>>        [Required]
>>        [DisplayName("Client No")]
>>        [UIHint("Number")]
>>        [Column("client_no", TypeName = "smallint")]
>>        [Remote("doesClientNoExist", "Client", HttpMethod = "POST",
>>            AdditionalFields = "ClientId",
>>            ErrorMessage = "Client Number already exists. Please enter a different Client Number.")]
>>        public virtual Int16 ClientNumber
>>        {
>>            get
>>            {
>>                if (Client == null)
>>                    return 0;
>>                else
>>                    return Client.Number;
>>            }
>>
>>            set { Client.Number = value; }
>>        }
>>
>>        [Required]
>>        [Column("client_name", TypeName = "varchar")]
>>        [DisplayName("Client Name")]
>>        [MaxLength(30, ErrorMessage = "Client Name should not be longer than 30 characters")]
>>        [MinLength(3, ErrorMessage = "Client Name is too short")]
>>        [Remote("doesClientNameExist", "Client", HttpMethod = "POST", AdditionalFields = "ClientId",
>>            ErrorMessage = "Client Name already exists. Please enter a different Client Name.")]
>>        public virtual string ClientName
>>        {
>>            get
>>            {
>>                if (Client == null)
>>                    return "";
>>                else 
>>                    return Client.Name;            
>>            }
>>
>>            set { Client.Name = value; }
>>        }
>>
>>        public int id { get; set; }
>>       /// <summary>
>>       /// Public constructor
>>       /// </summary>
>>       /// <param name="client"></param>
>>        public ClientViewModel(Client client = null)
>>        {
>>           if (client != null)
>>              this.Client = client;
>>           else
>>              this.Client = new Client();
>>        }
>>    }
>>}
>>
>>Could the error above be related to that public constructor? But I am using default value for the parameter in the constructor, so I don't think it means I do not have constructor without parameter?
>>
>>Can someone please lend a hand as where to look for the problem?
>>
>>My dialog is defined this way:
>>
>>
>>var $dlg = $("#add-edit-dialog").dialog({
>>   autoOpen: false,
>>   show: "blind",
>>   closeOnEscape: true,
>>   resizable: true,
>>   width: 1200,
>>   height: 750,
>>   minHeight: 600,
>>   minWidth: 950,
>>   buttons: {
>>      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');
>>         } else return false;
>>
>>      },
>>      Cancel: function () {
>>         $(this).dialog("close");
>>         clearForm();
>>         if (validator)
>>            validator.resetForm();
>>      }
>>   },
>>   close: function () { clearForm(); },
>>   open: function () {
>>   }
>>});
>>
>>Thanks a lot in advance.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform