Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Troubles with jquery ui dialog and save method
Message
 
 
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:
01569866
Views:
22
>>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?
>
>The answer is the first line of the error. A constructor with an optional parameter is *not* a parameterless constructor...
>
This is what I started to think. I'll try to just add

public ClientViewModel
{
}

and see if this will resolve the problem.
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