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
Post a Comment