我有以下型號:如何在asp.net MVC 4和Razor視圖中顯示來自路徑的圖像?
public class Player
{
public String ImagePath
{
get
{
return "~/Content/img/sql_error.JPG";
}
}
而且,這是我的.cshtml
文件:
@model SoulMasters.Models.Game.Player
@{
ViewBag.Title = "Game";
Layout = "~/Views/Shared/_GameLayout.cshtml";
var imagePath = @Model.ImagePath;
}
<fieldset>
<legend>Player</legend>
<div class="display-field">
@Html.DisplayFor(model => model.ImagePath)
</div>
@imagePath
<div style="padding:10px;">
<img [email protected] alt="Sample Image" width="300px" />
<img alt="asd" >
model.ImagePath;
</img>
</div>
</fieldset>
結果是簡單的文字:
~/Content/img/sql_error.JPG
~/Content/img/sql_error.JPG
Sample Image asd model.ImagePath;
另外,我曾嘗試以下線,它的工作原理:
<img src="~/Content/img/sql_error.JPG" alt="Sample Image" width="300px" />
如何從路徑顯示該圖像? 根據設置,圖像路徑可能會有所不同嗎?任何其他想法?
我現在還不知道如何使用剃刀語法。
試試這個'' –