我有以下型号: 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/
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" />
如何从路径显示该图像?
根据设置,图像路径可能不同吗?还有其他想法吗?
关于剃刀语法是如何工作的,我现在还没有真正理解它.
在你的视图中尝试这样<img src= "@Url.Content(Model.ImagePath)" alt="Image" />
