【发布时间】:2017-06-04 02:02:09
【问题描述】:
所以我想在数据库中获取该图像的title。我该怎么做?它为所有图像显示Describe your post...而不是数据库中图像的实际标题
https://i.gyazo.com/17828889116a77983f70fd8c8a4c2ebf.png
查看:
@foreach (var image in Model.Images)
{
<h2>@Html.LabelFor(m => m.title)</h2>
<div class="row">
<div class="col-md-8 portfolio-item">
<img class="portrait" src="@Url.Content(image)" alt="Hejsan" />
</div>
</div>
}
型号
[Table("MemeImages")]
public class UploadFileModel
{
[Key]
[DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]
public int id { get; set; }
public string location { get; set; }
public IEnumerable<string> Images { get; set; }
public int contentLength { get; set; }
public string contentType { get; set; }
public string userID { get; set; }
[Required]
[Display(Name = "Describe your post...")]
public string title { get; set; }
public void SavetoDatabase(UploadFileModel file)
{
ApplicationDbContext db = new ApplicationDbContext();
db.uploadedFiles.Add(file);
db.SaveChanges();
}
}
【问题讨论】: