这是模型。
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" />
和这个工作
如何从路径显示该图像?
模型图像路径可以根据设置而不同。
任何其他想法?
我现在不知道如何剃刀语法工作。
谢谢,
Gabriel Sas
解决方法
在你的视图尝试这样
<img src= "@Url.Content(Model.ImagePath)" alt="Image" />
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。