When Iam doing a project i got confused in a place to retrieve only unique value from table. for that i distinct , groupby clauses in the linq query, but I got some error . I have two tables and the id of category table is foreign key and I need to retrieve only distinct id from the another gallery table
model
public partial class Gallery
{
public int Id { get; set; }
public int CategoryId { get; set; }
public string ImageTitle { get; set; }
public string Image { get; set; }
public virtual Category Category { get; set; }
}
public Category()
{
this.Galleries = new HashSet<Gallery>();
}
public int Id { get; set; }
public string CategoryName { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Gallery> Galleries { get; set; }
}
this is the model the categoryid is the foreign key to the gallery class
controller
public ActionResult GalleryCata()
{
var res = db.Galleries.ToList();
return View(res);
}
view
@model List<ThaniyamBank.Models.Gallery>
@for (var j = 0; j < Model.Count(); j++)
{
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="hovereffect">
<img src="@Url.Content("~/GalleryImages/" + @Html.DisplayFor(m => m[j].Image))" class="img-responsive" alt="" />
<div class="overlay">
<h2>@Html.DisplayFor(m => m[j].Category.CategoryName) </h2>
<a class=" fancybox info " href="@Url.Content("~/GalleryImages/" + @Html.DisplayFor(m => m[j].Image))" data-fancybox-group="gallery"><i class="fa fa-eye" aria-hidden="true"></i></a>
<a class="info " href="gallery.html"><i class="fa fa-link" aria-hidden="true"></i></a>
</div>
</div>
</div>
}
I need to display the images based on the category. when i run the application i get all the images from the table and not by based on the category . can anyone please help me to solve the problem ??
1[System.Int32]', but this dictionary requires a model item of type 'System.Collections.Generic.List1[A.Models.Gallery]'. - user256