asp.net mvc - MVC5 Razor input images to controller from view -


in mvc application try add multiple image insert view have viewmodel fields. call controller 1 common button.

@using (html.beginform()) {     <form action="" method="post" enctype="multipart/form-data">                                        <div>       <input id="fileupload" type="file" multiple="multiple" name="files" />      </div>     </form>      <div>        .... textbox etc. (insertviewmodel)      </div>     <div class="form-group">      <div class="col-md-offset-8 col-md-10">        <input type="submit" value="create" class="btn btn-primary" />      </div>     </div> } 

my controller looks:

 [httppost] public async task<actionresult> insert(insertviewmodel model, ienumerable<httppostedfilebase> files)  { ..... } 

but allways count of files object 0.

any idea?

please add submit button form , text box also. works fine. code in view

<form action="" method="post" enctype="multipart/form-data"> <div>     <input id="fileupload" type="file" multiple="multiple" name="files" /> </div> <div>     <input id="name" type="text"  name="name" /> </div> <div>     <input id="address" type="text" name="address" /> </div> <div class="form-group">     <div class="col-md-offset-8 col-md-10">         <input type="submit" value="create" class="btn btn-primary" />     </div> </div> 

hello

my controller like

 [httppost]     public actionresult index(ienumerable<httppostedfilebase> files, demo obj)     {         return view();     } 

multipleuploadfilebinded

classobjectbinded

and if need 2 form in single view can send upload file , receive controller using request.files

 if (request.files.count > 0)//// image uplaod browse button  {                foreach(var fl in request.files)                {                     var inputstream = request.files[0].inputstream;                }    } 

like above can stream of file , etc.


Comments

Popular posts from this blog

.net - Bulk insert via Dapper is slower than inserting rows one-by-one -

shared memory - gstreamer shmsrc and shmsink with h264 data -

python - Error importing VideoFileClip from moviepy : AttributeError: 'PermissionError' object has no attribute 'message' -