asp.net mvc - MVC || HTML Form || Object reference not set to an instance of an object -
i error , dont know how on come it:
"object reference not set instance of object."
line 48: public actionresult upload(imagefile imagefile) line 49: { line 50: foreach (var image in imagefile.files) line 51: { line 52: if (image.contentlength > 0)
i tried using id attribute , name attribute , not...
this problematic section in controller :
[httppost] public actionresult upload(imagefile imagefile) { foreach (var image in imagefile.files) { if (image.contentlength > 0) { cloudblobcontainer blobcontainer = _blobstorageservice.getcloudblobcontainer(); cloudblockblob blob = blobcontainer.getblockblobreference(image.filename); blob.uploadfromstream(image.inputstream); } } return redirecttoaction("upload"); }
this html.form :
<p> @using (html.beginform("upload", "home", formmethod.post, new { enctype = "multipart/form-data" })) { <input type="file" name="imagefile" id="imagefile" multiple /> <input type="submit" name="submit" value="upload" /> } </p>
and "imagefile" class :
public class imagefile { public ienumerable<httppostedfilebase> files { get; set; } }
what i'm doing wrong ? read lot of posts exception none of them helped me..
thank you.
just change name of html input files, in model class:
your input element in view:
<input type="file" name="files" id="files" multiple />
your model:
public class imagefile { public ienumerable<httppostedfilebase> files { get; set; } }
Comments
Post a Comment