こんにちは私が以前に行ったWebアプリケーションからこのコードを持っています。私はちょうどコピーして新しいものに貼り付けましたが、画像は新しいサイトに表示されません。私はパスを表示するコードを入力しても、それはidを表示するためにokを表示し、それはokと製品のすべてのプロパティを表示し、すべて表示されますがイメージは表示されません。いつF5私のアプリは、サイトが正常に実行されます。イメージの代わりにimgをロードできない場合は小さなアイコンしか表示されません。ブラウザのインスペクタを使用する場合、src属性はイメージから正しいパスを持ちます。 私はここにコード私のコードに画像を表示する際に間違いを見つけられない
これは
namespace Mysite.Models
{
public class Category
{
//[ScaffoldColumn(false)]
public int CategoryID { get; set; }
[Display(Name = "Category Name")]
public string CategoryName { get; set; }
//[Display(Name = "Product Description")]
public string Description { get; set; }
public string ImagePath { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
}
CATEGORYクラスであり、これはこれは、そのメソッドの参照を持っているCategoryControllerある
namespace Mysite.Models
{
public class Product
{
//[ScaffoldColumn(false)]
public int ProductID { get; set; }
[Required, StringLength(100), Display(Name = "Product Name")]
public string ProductName { get; set; }
[Required, StringLength(10000), Display(Name = "Product Description"), DataType(DataType.MultilineText)]
public string Description { get; set; }
public string ImagePath { get; set; } // Here is the image path that I want to show
public int? CategoryID { get; set; }
public virtual Category Category { get; set; }
}
}
製品のクラスではあり に間違っているものを見つけることができません含まれています製品
namespace Mysite.Controllers
{
public class CategoriesController : Controller
{
private ProductContext db = new ProductContext();
public ActionResult Browse(string categories)
{
var categoriaModel = db.Categories.Include("Products")
.SingleOrDefault(c => c.CategoryName == categories);
return View(categoriaModel);/*(db.Categories.C)*/
}
NDこれは実際に
@model Mysite.Models.Category
@{
ViewBag.Title = "Browse";
}
<h2>Browse</h2>
@foreach(var item in Model.Products) {
<p>@item.ProductName , @item.ProductID , @item.ImagePath</p>
<img src="@item.ImagePath"/>
}
を示したが、これは、それが実際に示したものです取得し、私はブラウザに表示したいすべてのかどうかをテストするための簡略図である
Horizontal Faux Wood , 1 , Content/ProductImages/woodblind2.jpg /*small non-loaded picture icon here*/
Horizontal Real Wood , 2 , Content/ProductImages/woodblinds1.jpg /*small non-loaded picture icon here*/
Aluminium mini blinds , 10 , Content/ProductImages/aluminiumminiblind.jpg /*small non-loaded picture icon here*/
私は別のそれを持って、これと同じコードサイトの作業。 私はimagesフォルダ、ルートを再確認し、すべてがOKである
これは働いたものです。しかし、なぜこれだけではなく、他のものでさえも他人でさえOKではない(明らかに) – shark6552