I have a following POCO class. I don not want the parameterless constructor to be public.
public class FileDownloadRequest
{
//public FileDownloadRequ
Yes, you can use any constructor you like, but you will have to do the model binding yourself then. The problem is in DefaultModelBinder.CreateModel
, which uses a parameterless public constructor.
You have to override the default model binder and create your own. If that is worth the time is up to you.
Steps to take:
CreateModel
;modelType
for some generic constraint which models you need to call the constructor with parameters on;bindingContext
;ModelBinder
attribute, or globally.Read more on custom bindings here.