Add photos and gallery to an ASP MVC product

Asked

Viewed 158 times

2

I’m starting in Asp.net using mvc 5, I’ve taken some basic courses, and now I want to make a simple little complex virtual store. but I am in a crucial doubt in the product table, it will have a thumbnail photo and more the others in its description,

public class Produto
{

    public int PRODUTOID { get; set; }

    public int CATEGORIAID { get; set; }

    public string NOME { get; set; }


    [Display(Name = "Imagem")]
    [DataType(DataType.ImageUrl)]
    public string FOTO { get; set; }

    public decimal PRECO_UNITARIO { get; set; }

    public string QUANTIDADE_ESTOQUE { get; set; }


    public virtual ICollection<Categoria> Categoria { get; set; }
}

My question is how do I add more image to that product when the person goes to see product details? i would have to create another table "gallery" and relate to the product in question?

  • If you want to have an unlimited number of images for your products, which is more common, you will need to create another table to store these urls. If it’s a restricted number, you can simply add new columns like FOTO_UM, FOTO_DOIS and etc... (What’s not elegant at all)

1 answer

0


Yes, it’s possible to do everything in one string only

Voce can put all images in the same field FOTO and separate fonts using ";" and when the user makes the call you only need to add the .split(";") and returns the list of images.

example:

string[] fotos= FOTO.Split(';');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.