Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. public class Image
  2. {
  3. public int ID { get; set; }
  4. public string ImagePath { get; set; }
  5. public string Category { get; set; }
  6. }
  7. public class ImageDBContext : DbContext
  8. {
  9. public DbSet<Image> Images { get; set; }
  10. }
  11. }
  12.  
  13. [HttpGet]
  14. public ActionResult Search(string category)
  15. {
  16. var myList = db.Images.ToList();
  17. if (!string.IsNullOrEmpty(category))
  18. {
  19. myList = db.Images.Where(s => s.Category == category).ToList();
  20. }
  21.  
  22. return View(myList);
  23. }
  24.  
  25. <button>@Html.ActionLink("Extras", "Search", new { Category = "Extras" })</button>
  26. <button>@Html.ActionLink("Home", "Search", new { Category = "Home" })</button>
  27.  
  28. <div style="width:800px; margin:200px auto; text-align:center;">
  29. <ul class="images">
  30. @foreach (var item in Model)
  31. {
  32. var imagePath = @item.ImagePath;
  33. imagePath = "/Images/" + imagePath;
  34. <li class="image-item" style="background: url(@imagePath) no-repeat;"></li>
  35. }
  36. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement