我有以下模型:
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 src=@imagePath 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" />
如何从路径显示该图像?图像路径会根据设置而有所不同吗?还有其他想法吗?
我现在不太了解剃刀语法的工作原理。