[英]Asp.Net MVC Controller and View
我有一個控制器,它返回一個圖像。
我認為,我有:
@model MyShop.Models.Car
....
<img src="@Url.Action("myimage", "Image", new { code = model.Code, imageFile = model.imageFile })" class="img-responsive">
我有一個錯誤,因為未定義模型。 如果我用
@Html.DisplayFor(model => model.Name)
工作正常。 如何在第一個代碼段中引用當前項目?
謝謝
您還需要返回模型圖像路徑,以及項目中圖像的位置。
<img src= "@Url.Content(Model.ImagePath)" alt="Image" />
試試這個:將model.Code
更改為Model.Code
<img src="@Url.Action("myimage", "Image", new { code = Model.Code, imageFile = Model.imageFile })" class="img-responsive">
或者,如果您在imageFile
具有完整的圖像路徑, imageFile
嘗試:
<img src="@Model.imageFile" alt="your image" class="img-responsive"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.