asp.net mvc 5 - Image gallery in MVC 5 -


i'm working on image gallery (or products images) , getting weird error in uploadimagemethod in productscontroller. here's method, i'll explain error is:

[httppost] public actionresult uploadimagemethod() {     //make sure have files upload     if (request.files.count != 0)     {         //parallel.for loop loop through each image being uploaded         parallel.for(0, request.files.count, index =>             {                 //new httppostedfilebase hold each image                 httppostedfilebase file = request.files[index];                  //get file size                 int size = file.contentlength;                  //get file name                 string name = file.filename;                  //save image our desired directory                 file.saveas(server.mappath("~/content/productimages/") + name);                  //now create new product , set it's properties                 product p = new product()                 {                     productid = guid.newguid(),                     productname = name,                     productimages.add(new productimage() { path = server.mappath("~/content/productimages/") + name, alttext = name })                 };                  //add database                 db.products.add(p);                  //save changes                 db.savechanges();             });         return content("success");     }     return content("failed"); } } 

i'm getting error on line:

productimages.add(new productimage() { path = server.mappath("~/content/productimages/") + name, alttext = name }) 

it says "invalid initializer member declarator" , says productimages not exist in current context. if need see product class here is:

public class product {     public product()     {         productimages = new list<productimage>();     }      public int productid { get; set; }      public string productname { get; set; }     public double productprice { get; set; }     public int productquantity { get; set; }      public virtual list<productimage> productimages { get; set; } } 

can tell me i'm doing wrong?

edit

when way no errors

var p = new product();      p.productid = guid.newguid();     p.productname = name;     p.productimages.add(new productimage() { path = server.mappath("~/content/productimages/") + name, alttext = name }); 

anyone have explanation me?

try image galary in mvc

http://www.c-sharpcorner.com/uploadfile/b696c4/creating-image-gallery-in-mvc-5-application631/

http://www.aspdotnet-suresh.com/2014/12/create-image-photo-gallery-in-aspnet-mvc-in-jquery-using-csharp.html


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -