私は次のモデルがあります:asp.net MVC 4とRazorビューのパスから画像を表示するには?
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 [email protected] 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" />
パスからそのイメージを表示するにはどうすればよいですか? イメージパスは設定によって異なる場合がありますか?他のアイデア?
剃刀の構文がどのように機能するかは実際には分かりません。あなたのビューで
この '' –