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

后端 未结 6 1898
情话喂你
情话喂你 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 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.

提交回复
热议问题