No parameterless constructor defined for this object. in ASP.NET MVC Controller

后端 未结 6 1841
情话喂你
情话喂你 2021-01-11 19:19

I am sure this is quite straightforward but I am a bit stuck here. The routing defined for my app is just the default. I have the following controller defined.



        
相关标签:
6条回答
  • 2021-01-11 19:52

    If DocumentEditViewModel constructor's accessibility level is protected you will get also the same error.

    0 讨论(0)
  • 2021-01-11 20:04

    Most likely you have dependency injections mechanism. But MVC requires "special" way to register container. Look at this link Adding Unity to Your Web Applications, patterns and practices

    0 讨论(0)
  • 2021-01-11 20:04

    I had a slightly different problem. One of my Model classes was abstract.

    0 讨论(0)
  • 2021-01-11 20:11

    add to class DocumentEditViewModel default constructor

    public DocumentEditViewModel (){}
    
    0 讨论(0)
  • 2021-01-11 20:17

    The MVC framework is trying to create an instance of the DocumentViewModel class but it can't find a publicly accessible default constructor (that does not take any arguments). You can either define such a default constructor like @simplyDenis suggested or define a cusotm ModelBinder that can create the instance using your custom constructor.

    0 讨论(0)
  • 2021-01-11 20:18

    Does DocumentEditViewModel have a parameterless constructor? I believe this is needed for modelbinding on your post view.

    0 讨论(0)
提交回复
热议问题