Reputation: 51
So I want to get the title
for that image in the database. How do I do it? It's showing Describe your post...
for all images instead of the actual title of the image in the database
https://i.gyazo.com/17828889116a77983f70fd8c8a4c2ebf.png
View:
@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>
}
Model
[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();
}
}
Upvotes: 0
Views: 305
Reputation: 613
Remove the display attribute.
[Required]
public string title { get; set; }
Also, LabelFor() is not the right thing. You may want to use Display/DisplayFor() to render the value.
Upvotes: 0