簡體   English   中英

Asp.Net MVC控制器和視圖

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM