dbo.Images - 表 http://imgur.com/g1suOTj如何在这种情况下执行where子句?
Image.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
public class ImageController : Controller
{
private ImageDBContext db = new ImageDBContext();
public ActionResult Index(int ImageID)
{
return View(db.Images.Where(img => img.ID == ImageID).ToList());
}
Index.cshtml
@model IEnumerable<MvcMovie.Models.Image>
@{
ViewBag.Title = "Index"; }
<img src="~/Images/@Html.DisplayFor(ImagePath.Where(ImageID == 2))" />
参考上面的代码,我试图通过选择相关的ID
从表中显示ImagePath
。有@Html.DisplayFor
检索和查看图像'ImagePath'
Where
ID
值2或3或4.有了这个工作成功,我将能够输入任何URL存储的图像数据库上.cshtml
个别。下面的代码并不显示具有ID
形象价值2
<img src="~/Images/@Html.DisplayFor(ImagePath.Where(ImageID == 2))" />
任何想法?
非常感谢您的帮助和时间。
如果你要运行一个where查询,那么你不需要我认为的foreach循环。你的问题不是很清楚...... – scartag
问题已更新。 –
您已经将控制器返回的内容限制为仅限特定ID,并且只能显示此图像。 – scartag