modelbinders - Input file autobind to byte[] aray in ASP.NET MVC -


Has any managed to get any default bundler to work with input file control and type byte array property?

If I have a property on my ViewModel name and the file input control is on my view name, then the default binder issues this error:

The input is valid Base-64 is not string as it contains a non-base 64 character, more than two padding characters, or a non-white space character in padding characters.

Why do you need a byte [] array? ? The default model binder works with:

  & lt;% use (HTML.biz form ("upload", "home", formmath.post, new {enctype = "multipart / form -data "})) {% & Gt; & Lt; Input type = "file" name = "file" id = "file" /> & Lt; Input type = "submit" value = "upload" / & gt; & Lt;%}% & gt;  

and this is the controller action that will handle it:

  [HTTP post] Public action uploads (HTTP posted filebase file) {if (file.ContentLength & gt ; 0) {Var filename = path Gatefilename (file filename); Var path = path Combine (Server MapPath ("~ / App_Data"), Filename); File.SaveAs (Path); } Redirect return action ("index"); }  

It works with multiple files

You can simply enter the IEnumerable & lt; HttpPostedFileBase & gt; Use .

Comments