HttpPostedFileBase - 0 bytes in POST for the base view model property only

I correctly placed the image and binding to the HttpPostedFileBase property in my view model, but when I put the same property in the base class of the view model, it does not model byte binding. It still shows the image name, but not the content stream.

I tested everything I could think of. Please, help!

These paintings tell the whole story: enter image description hereenter image description hereenter image description hereenter image description hereenter image description here

Thanks in advance. Let me know if something is unclear.

UPDATE

I think this is a legitimate mistake. I tried all the suggestions below (starting at 1/26) before posting on SO. I also tried: 1. Creating a base property as virtual and overriding it in a child class 2. Creating a new property in a child class that just gets / sets the base property

My solution, which is far from elegant, is to add a β€œtemporary” property to the child class, and the first thing in the MVC action method is setting the base property for it. I hope that the present solution is introduced, and I can return this cloodge and make the correct correction.

+6
source share
1 answer

If it were me, I would create a v.simple custom binder for the model class and manually run it. It will probably be easier to do this (and more obvious for future maintenance) than to try to uncover the flaws of DefaultModelBinder. In addition, this would mean that you would not have to (unnecessarily) pollute your models / controller actions / unit tests.

Here is a good article on how to create a binder based on a standard binder: http://www.codeproject.com/Articles/605595/ASP-NET-MVC-Custom-Model-Binder .

NTN

0
source

Source: https://habr.com/ru/post/981520/


All Articles