简体   繁体   English

具有许多上传图像的对象

[英]object with many uploaded images

I'm building a simple web app. 我正在构建一个简单的Web应用程序。 Scenario is the following. 场景如下。

  1. Image upload 图片上传
  2. Create new object with selecting one or more images (previously uploaded) 选择一个或多个图像(先前已上载)创建新对象
  3. Display object wiht corresponding image(s) 显示具有相应图像的对象

I was thinking to create something like this 我在想创造这样的东西

SampleObject.cs
    Guid Id {get; set;}
    string Name {get; set;}

Image.cs
Guid Id {get; set;}
string Name {get; set;}
string ImagePath {get; set;}
SampleObject SampleObject {get; set;}

But on the other hand I only need SampleObjects with many ImagePath strings. 但另一方面,我只需要具有许多ImagePath字符串的SampleObjects。 So better the way would be to simplify this to have only SampleObjects with many strings (ImagePath). 因此,简化此操作以使只有具有许多字符串的SampleObjects(ImagePath)的方式更好。

So, the second scenario would be like following 所以,第二种情况就像是下面的情况

  1. Upload image 上传图片
  2. Create object and using jquery onclick select one or many images (read img src element) and store these strings inside SampleObject list of strings. 创建对象并使用jquery onclick选择一个或多个图像(读取img src元素)并将这些字符串存储在SampleObject字符串列表中。

Do the second scenario seems better to you, and if it does how would you create these entities (sampleobject.cs and image.cs). 第二种情况对您来说似乎更好,如果它确实如何创建这些实体(sampleobject.cs和image.cs)。

I would approach this problem like this: 我会像这样处理这个问题:

Create a simple Model for any Image you may have. 为您可能拥有的任何图像创建一个简单的模型。

public class UploadedImageModel
{
    public string ImagePathUrl { get; set; }
    public string AlternateText { get; set; }
}

Create a simple ViewModel that has a collection of Images you may want to display. 创建一个简单的ViewModel,其中包含您可能要显示的图像集合。

public class ImageGalleryViewModel
{
    public List<UploadedImageModel> Images { get; set; }
}

Then in your View: 然后在你的视图中:

@model MyApp.WebUI.Models.ImageGalleryViewModel

@foreach(var pic in Model.Images) {

    <img src="pic.ImagePathUrl" alt="pic.AlternateText" /> 

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM