[英]object with many uploaded images
I'm building a simple web app. 我正在构建一个简单的Web应用程序。 Scenario is the following.
场景如下。
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 所以,第二种情况就像是下面的情况
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.