ASP.Net MVC 2 Image upload -


i trying simple image upload using mvc2. in view have:

<% using (html.beginform("upload","home")) { %>      <input type="file" name="upload" id="imageupload" value="upload image"/>     <input type="submit" value="upload" /> <% } %> 

in controller (home), how image uploaded , save database? new asp.net mvc , thing has got me stuck. in advance , time.


edit:

okay, guess question vague answer got provide more detail , have:

the image model simple below --

public class imagemodel {     public image image;     public string imagename;      public imagemodel(image image, string name)     {         this.image = image;         imagename = name;     }  } 

the view this:

<%using (html.beginform("upload","home", formmethod.post, new {enctype = "multipart/form-data"})) {%>         <input type="text" id="imagename" />     <input type="file" name="upload" id="imageupload" value="upload image"/>     <input type="submit" value="upload" /> <%} %> 

the controller want create new imagemodel instance, validate , if valid save database: have:

    public actionresult upload(imagemodel image)     {         //this stuck?         //how supplied image part of imagemodel object         //whats best way retrieve supplied image          imagemodel temp = image;         if(!temp.isvalid()){             //get errors              //return error view         }         uploadrepository.saveimage(temp);               return view();     } 

the question how supplied image , save database

based on view code try changing model this...

public class imagemodel {     public httppostedfilewrapper upload { get; set; }     public string imagename { get; set; }  } 

also, you'll need name text input element (not id)...

<input type="text" id="imagename" name="imagename" /> 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -