No parameterless constructor defined for this object.
-
06-07-2021 - |
Question
Currently I've got a runtime exception: 'Systen.MissingMethodException : No parameterless constructor defined for this object.
I've googled and came across a lot of people actually not having a default contstructor, though my code actually does, so I don't know where it goes wrong!
My full code can be found here on pastebin since its varely large: http://pastebin.com/RxdKgxSx
Thanks for your help!
Solution
Replace:
public ActionResult Create(UploadViewItem viewItem, HttpPostedFile postedFile)
with:
public ActionResult Create(UploadViewItem viewItem, HttpPostedFileBase postedFile)
ASP.NET MVC works with abstractions over the actual HttpContext
objects (HttpContextBase
, HttpRequestBase
, HttpResponseBase
, HttpSessionBase
, HttpPostedFileBase
, ...).
That's what allows for easier unit testing and mocking those objects.
For more information about uploading files in ASP.NET MVC you may checkout the following blog post.