I'm building a simple web app. 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. So better the way would be to simplify this to have only SampleObjects with many strings (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).
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.
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" />
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.