如何从路径asp.net mvc的4和剃刀视图中显示图像 [英] how to display image from path in asp.net mvc 4 and razor view
本文介绍了如何从路径asp.net mvc的4和剃刀视图中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是模型。
public class Player
{
public String ImagePath
{
get
{
return "~/Content/img/sql_error.JPG";
}
}
这是我的.cshtml
和我的尝试:
this is my .cshtml and what i tried:
@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>
结果是简单的文字:
the result is simple text:
~/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" />
和这个作品
如何显示从路径形象?
模型图像路径可以是不同的,是根据设置。
任何其他的想法?
how to display that image from path? the model image path can be different, based on settings. any other ideas?
我真的不明白现在剃刀语法是如何工作的。
i don't really get it now on how razor syntax works.
谢谢,
加布里埃尔SAS
thanks, Gabriel Sas
推荐答案
在您查看尝试像这样
<img src= "@Url.Content(Model.ImagePath)" alt="Image" />
这篇关于如何从路径asp.net mvc的4和剃刀视图中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文