c# - upload files in asp.net mvc -


i'd upload file in asp.net mvc. i've following codes. file returns null value. there anything, should try?

.cshtml

<input type="file" name="file" id="file" /> 

controller.cs

   [httppost]     public actionresult index(bookmodel model, httppostedfilebase file, formcollection values)     {         try         {             if (!modelstate.isvalid)             {                 return view("index", new bookmodel());             }              if (file != null && file.contentlength > 0)             {                                     var filename = path.getfilename(file.filename);                                     var path = path.combine(server.mappath("~/img/"), filename);                 file.saveas(path);                  model.imageurl = filename;             }            //sendmail();         }         catch (exception ex)         {                            return view("index", new bookmodel());         }          return view("success");     } 

add form enctype="multipart/form-data"


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -