c# - mvc 5 update bind attribute in submit -
i have mvc 5 entity framework application, database first , new mvc. have file picker control selects image , in action result class of create view, encode picture storage in sql. have encoding correct, data view in bind attributes , want update property bind encoded picture before write database. when try write database, whole app churns until runs out of memory. obviously, missing piece.
view: div filepicker , place entity framework wanted coded pic go.
<div class="col-md-10"><br/><br/> @html.textbox("beforeencode", "", new { type = "file" })<br /> @html.labelfor(model => model.fldphoto, htmlattributes: new { @class = "control-label col-md-2" }) @html.editorfor(model => model.fldphoto, new { htmlattributes = new { @class = "form-control"} }) @html.validationmessagefor(model => model.fldphoto, "", new { @class = "text-danger" }) </div> </div>
controller: controller irrelevant parts deleted. have breakpoint set on db.savechanges(); line checking if there issue encoding, removed, churns
public actionresult create([bind(include = "fldphotoid,fldphoto,beforeencode")] tblphoto tblphoto, string beforeencode) { var fileupload = beforeencode; try { if (modelstate.isvalid) { if (fileupload != null) { filestream fs; fs = new filestream(beforeencode, filemode.open, fileaccess.read); byte[] picencoded = new byte[fs.length]; fs.read(picencoded, 0, convert.toint32(fs.length)); fs.close(); tblphoto.fldphoto = picencoded; } db.tblphotoes.add(tblphoto); db.savechanges(); return redirecttoaction("index", "home"); }
Comments
Post a Comment