我有以下模型:
public class Player
{
public String ImagePath
{
get
{
return "~/Content/img/sql_error.JPG";
}
}
而且,这是我的.cshtml
file:
@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" />
如何显示路径中的图像?
图像路径会根据设置而不同吗?还有其他想法吗?
我现在不太明白 razor 语法是如何工作的。
在你的视图中尝试这样
<img src= "@Url.Content(Model.ImagePath)" alt="Image" />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)