Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Image
- {
- public int ID { get; set; }
- public string ImagePath { get; set; }
- public string Category { get; set; }
- }
- public class ImageDBContext : DbContext
- {
- public DbSet<Image> Images { get; set; }
- }
- }
- [HttpGet]
- public ActionResult Search(string category)
- {
- var myList = db.Images.ToList();
- if (!string.IsNullOrEmpty(category))
- {
- myList = db.Images.Where(s => s.Category == category).ToList();
- }
- return View(myList);
- }
- <button>@Html.ActionLink("Extras", "Search", new { Category = "Extras" })</button>
- <button>@Html.ActionLink("Home", "Search", new { Category = "Home" })</button>
- <div style="width:800px; margin:200px auto; text-align:center;">
- <ul class="images">
- @foreach (var item in Model)
- {
- var imagePath = @item.ImagePath;
- imagePath = "/Images/" + imagePath;
- <li class="image-item" style="background: url(@imagePath) no-repeat;"></li>
- }
- </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement