file upload - asp.net mvc-5 HttpPostedFileBase is null -


this question has answer here:

i messing around file uploading using asp.net mvc-5 httppostedfilebase showing me httppostedfilebase null after selecting image

here code

 <input type="file" title="search image" file-model="profileimage" id="allfilepath" name="file" />  <button type="submit" class="btn btn-primary col-sm-5">          <span class="glyphicon glyphicon-plus"></span>  </button> 

and controller

    [httppost]     public actionresult insert(httppostedfilebase file, quotationcompany quotecomp)     {         var allowedextensions = new[] {         ".jpg", ".png", ".jpg", "jpeg"     };         if (file == null)         {             viewbag.message = "please select image";             return view();         }         else {             viewbag.message = "image uploaded successfully";             return view();         }      } 

if (file == null)(on line (file) showing me null after uploading png image)

what wrong in code?

check form attributes

a common mistake people make missing following part in form tag:

<form enctype="multipart/form-data"> </form> 

also in mvc form structure this

@using (html.beginform("action", "controller", formmethod.post, new { @enctype = "multipart/form-data", @id = "myform", @role="form" })) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -