mvc c# file upload as byte array -


i have upload files , other data in single submit of uploadfile.cshtml form

i have base class input of mvc action in home controller.

my base class, mvc action method , cshtml part razor script given below

i have file byte array in mvc action while submitting uploadfile.cshtml form

my base class

public class fileupload {   public string name {get;set;}   public int age {get;set;}   public byte[] photo {get;set;} } 

mymvcaction

[httppost] public void uploadfile(fileuploadobj) {   fileuploaddata=obj; } 

mycshtmlform

@modelmvc.models.fileupload @using(html.beginform("uploadfile","home",formmethod.post)) {  <fieldset> <legend>file upload</legend>  <div class="editor-label"> @html.labelfor(model=>model.name) </div> <div class="editor-field"> @html.editorfor(model=>model.name) </div>  <div class="editor-label"> @html.labelfor(model=>model.age) </div> <div class="editor-field"> @html.editorfor(model=>model.age) </div> <div class="editor-label"> @html.label("uploadphoto"); </div> <div class="editor-field"> <input type="file" id="photo" name="photo"/> </div> <p> <input type="submit" value="create"/> </p>  </fieldset>  } 

i think better achieve this:

[httppost] public actionresult uploadfile(fileupload obj)  {     using (var binaryreader = new binaryreader(request.files[0].inputstream))     {        obj.photo = binaryreader.readbytes(request.files[0].contentlength);     }        //return action result e.g. return new httpstatuscoderesult(httpstatuscode.ok); } 

i hope helps.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -