c# - Editing an entity that has a file - Default Model Binder Confusion -


i have model this

public class filedetail  {     public string url { get; set; }      [notmapped]     public httppostedfilebase file { get; set; }      public void uploadfile()     {         if (file != null)         {          try         {                 ...                 url = "data:image/png;base64," + convert.tobase64string(objimagebytes);              }         }         catch (exception ex)         {          }     } } 

i have edit/create view this

...  @model applicationbase.core.common.filedetail  @html.textboxfor(x => x.file, new { type = "file", accept = "*" })  ... 

when edit action , default modal binder loads file property string,

request.form {file=17382.jpg} 

when create action, default modal binder loads file httpfilecollectionwrapper

request.form {}  request.files {system.web.httpfilecollectionwrapper}     allkeys: {string[1]}     count: 1 

why happening ? should httpfilecollectionbase when create new entity runs perfect, when edit same entity binds file property string not file ?

whats problem here ?

edited

i not save file property db. use bind file type input field run uploadfile method. method gets file , create base64 string , put url property of filedetail.

then save entity db.

edited 2

    [httppost, actionname("create")]     public actionresult createconfirmed(filedetail detail)     {     ...     }      [httppost]     public actionresult edit(filedetail detail)     {      } 

make sure views have multipart forms this:

@using(html.beginform(action, controller, formmethod.post, new { enctype="multipart/form-data"}) { } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -