[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) +446I made some searches and I think it may be related to my model?
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?
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.