Thursday, 15 September 2011

asp.net mvc - MVC Upload Object reference not set to instance of an object -



asp.net mvc - MVC Upload Object reference not set to instance of an object -

following code cshtml page:

@using (ajax.beginform("quotepost", "quote", null, new ajaxoptions() { updatetargetid = "response", onsuccess = "onsuccesslogin", onfailure = "onfaillogin", httpmethod = "post" }, new { id = "frmquote", enctype = "multipart/form-data" })) { <div class="col-xs-3"> <input name="files" type="file" id="fileupload1" /> </div> <div class="col-xs-3"> <input type="submit" id="upload1" value="upload" class="btn btn-default" /> </div> }

in controller:

public jsonresult uploadquotebyimei(httppostedfilebase postedfile) { seek { if (postedfile.contentlength > 0) { var filename = path.getfilename(postedfile.filename); var path = path.combine(server.mappath("~/images/"), filename); postedfile.saveas(path); } homecoming json(null, jsonrequestbehavior.allowget); } catch(exception ex) { throw ex; } }

in js

$(document).on('click', '#upload1', function (e) { $('#frmquote').submit(); $.ajax({ url: "quote/uploadquotebyimei", type: "post", datatype: "json", success: function (data) { } }); });

note: in controller have returned null json concern parameter passed in postedfile of httppostedfilebase null.

please help me this.

links have followed http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx/

asp.net-mvc asp.net-mvc-4

No comments:

Post a Comment