[英]System.MissingMethodException: No parameterless constructor defined for this object. MVC4
[英]System.MissingMethodException: No parameterless constructor defined for this object in mvc4
我正在创建MVC 4应用程序,但遇到了一个奇怪的问题。 在一段时间后,我反复出现以下错误。
2017-08-23 17:18:19,985 [7]错误-System.MissingMethodException:没有为此对象定义无参数构造函数。 在System.RuntimeType.CreateInstanceSlow(布尔publicOnly,布尔skipCheckThis,布尔fillCache,StackCrawlMark和stackActivator)在System.RuntimeTypeHandle.CreateInstance(RuntimeType type,布尔publicOnly,布尔noCheck,布尔&canBeCached,RuntimeMethodHandleInternal&ctor,布尔&bNeedSecurityCheck)。 (类型类型,布尔型非公共)位于System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext,ParameterDescriptor parameterDescriptor)处于System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext,ModelBindingContext bindingContext) )在System.Web.Mvc.Async.AsyncControllerActionInvoker处的System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext,ActionDescriptor actionDescriptor)。<> c__DisplayClass25.b__1e(AsyncCallback asyncCallback,Object 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; }
}
只是直觉在这里。 基于堆栈跟踪,存在一个模型绑定程序不喜欢的问题。 您的DTO类是否具有无参数的构造函数?
我调试这类奇怪问题的方法是注释掉大多数模型,直到找到一个可行的版本。 然后逐步引入新属性。 这不是很快,但是至少您可以缩小范围并找到罪魁祸首。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.