【发布时间】:2015-08-01 22:49:45
【问题描述】:
dbo.Images - 表格
图像.cs
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; }
}
}
ImageController.cs
[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);
}
Search.cshtml
@model IEnumerable<MvcMovie.Models.Image>
@{
ViewBag.Title = "Search";
}
<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>
应用程序上面的代码当前将在dbo.Images 中找到的所有图像显示到具有两个按钮的search.cshtml 上,以便从包含Extras 或Home 的Category 中过滤987654331@表。尽管该页面应根据单击的 Category 按钮显示图像,但我遇到了如下错误。
任何想法如何解决它? 感谢您的帮助,并在此先感谢您。
【问题讨论】:
标签: c# html asp.net asp.net-mvc razor