Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No parameterless constructor defined for this object.

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!

like image 950
Mittchel Avatar asked Mar 18 '26 13:03

Mittchel


1 Answers

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.

like image 79
Darin Dimitrov Avatar answered Mar 21 '26 06:03

Darin Dimitrov