asp.net mvc 4 - MVC 4 File Upload not working -
i trying simple upload image httppostedfilebase in controller remaining null.
here page :
<% using(html.beginform("addpicture","album",formmethod.post,new{enctype= "multipart/form-data" })) { %> <%: html.validationsummary(true) %> <fieldset> <legend>picturemodel</legend> <div class="editor-label"> <%: html.labelfor(model => model.privacytypeid) %> </div> <div class="editor-field"> <%: html.dropdownlist("privacytypeid", null, new { name = "privacytypeid", title = "please select privacy type.", id = "privacytypeid" }) %> <%: html.validationmessagefor(model => model.privacytypeid) %> </div> <div> upload image: <input type="file" name="file1" /> </div> <p> <input type="submit" value="create" /> </p> </fieldset> and here controller of page:
[httppost] public actionresult addpicture(guid id, picturemodel model, httppostedfilebase file1) { try { if (modelstate.isvalid) { var file = request.files[0]; try { guid albumid = id; if (file1 != null) { .....
can please guide me have wrong? tried no results
change line:
upload image: <input type="file" name="file1" id="file1" /> and change this:
public actionresult addpicture(guid id, picturemodel model, httppostedfile file1)
Comments
Post a Comment