我正在创建一个mvc 4应用程序,并且陷入了一个奇怪的问题。我经过一段时间后反复出现错误。System.MissingMethodException:在mvc4中为此对象定义的没有无参数构造函数
2017-08-23 17:18:19,985 [7]错误 - System.MissingMethodException:没有为此对象定义的无参数构造函数。 在System.RuntimeTypeHandle.CreateInstance(RuntimeType类型,布尔publicOnly,布尔NOCHECK,布尔& canBeCached,RuntimeMethodHandleInternal &构造函数,布尔& bNeedSecurityCheck) 在System.RuntimeType.CreateInstanceSlow(布尔publicOnly,布尔skipCheckThis,布尔fillCache,StackCrawlMark & stackMark) 在System.Activator.CreateInstance(类型类型,布尔非公开) 在System.Activator.CreateInstance(类型类型) 在System.Web.Mvc.DefaultModelBinder.BindComplexModel(controllerContext controllerContext,ModelBindingContext的BindingContext) 在System.Web.Mvc .ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext,ParameterDescriptor parameterDescriptor) at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext,ActionDescriptor actionDescriptor) at System.Web.Mvc.Async.AsyncControllerActionInvoker。 <> c__DisplayClass25.b__1e
我使用可空类型以及选择列表的在我的模型类(AsyncCallback的AsyncCallback的,对象asyncState)。我有所有模型类中的默认构造函数。我的模型类的样本是这样的:
public class BiddingFirstStepModel
{
//--------------------------Default Constructor--------
public BiddingFirstStepModel() { }
//-----------------------------------------------------
public string jobname { get; set; }
public string jobtype { get; set; }
public int jobtypeid { get; set; }
public string jobreference { get; set; }
public string customername { get; set; }
public int? quantity { get; set; }
public string department { get; set; }
public int? departmentid { get; set; }
public string description { get; set; }
public DateTime? EndDate { get; set; }
public string customerid { get; set; }
public string rfqno { get; set; }
public string productpartname { get; set; }
public string productpartcode { get; set; }
public string designlocation { get; set; }
public DateTime? sopdate { get; set; }
public int? lifecycle { get; set; }
public string productapplication { get; set; }
public string enduser { get; set; }
public bool loa { get; set; }
public string JobOrderType { get; set; }
public string SeriesJobRefrence { get; set; }
//--------NPI------------
public string producthead { get; set; }
public Int64? expectedincreasequantity { get; set; }
public DateTime? initialsamples { get; set; }
public Int64? tentativequantity { get; set; }
public DateTime? ppap { get; set; }
public string manufacturinglocation { get; set; }
public string supplier { get; set; }
//------------Customer Return------------------
public Int64 quantitysupplied { get; set; }
public string dmaicno { get; set; }
//---------------------------------------------
public HttpPostedFileBase excelbom { get; set; }
public JobDTO jobdata = new JobDTO();
public SelectList DepartmentList { get; set; }
public SelectList JobTypeList { get; set; }
public SelectList CustomersList { get; set; }
public SelectList JobReferenceList { get; set; }
public SelectList JobList { get; set; }
public bool isedit = false;
public bool IsRevise = false;
public CustomersDTO[] CustomerData { get; set; }
//-----------------------------------------------------
public UserDTO userdetail { get; set; }
//-----------------------------------------------------
public string JobId { get; set; }
//---------------------Notification---------------------
public List<NotificationDTO> listofnotification { get; set; }
//-------------------------------------------------------
public JobDTO[] JobsArray { get; set; }
//-------------------------------------------------------------------
public List<CustomersDTO> CustomerDataList { get; set; }
}
我不能因为有时候,而其他时候它工作完全正常的方法抛出这个错误来解决此错误。
任何帮助将不胜感激,因为我长期受到此打击。提前致谢。
UserDTO类是这样的:
public class UserDTO : IUserDTO
{
public Int64 Id { get; set; }
public string UserId { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public int DepartmentId { get; set; }
public string Email { get; set; }
public int UserPrivilegeId { get; set; }
public int LocationId { get; set; }
public DateTime CreatedOn { get; set; }
public DateTime? ExpiredOn { get; set; }
public byte[] Image { get; set; }
public DateTime? DateOfBirth { get; set; }
public string MobileNo { get; set; }
public string DepartmentName { get; set; }
public string UserPrivilege { get; set; }
public string LocationName { get; set; }
public string CreatedBy { get; set; }
public string ImageName { get; set; }
public string ImageExtension { get; set; }
public Int64? ImageSize { get; set; }
public string ImageSavePath { get; set; }
public string ImageShowPath { get; set; }
public string EditedBy { get; set; }
public DateTime? EditedOn { get; set; }
public string LocationShortName { get; set; }
}
“UserDTO”的模型是什么 - 是否包含无参数构造函数? (同样为'CustomersDTO'和'NotificationDTO'和'JobDTO') –
这个声明看起来很可疑:'public UserDTO userdetail {get;组; }'。模型类是否有一个用于绑定的空参数构造器? –
@StephenMuecke先生UserDTO,CustomersDTO,NotificationDTO和JobDTO是我共享层中的类。我在控制器中创建这些类的对象,然后将数据传递给数据访问层。 –