I have the following model:
public class Player { public String ImagePath { get { return "~/Content/img/sql_error.JPG"; } }
And, this is my .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>
The result is simple text:
~/Content/img/sql_error.JPG ~/Content/img/sql_error.JPG Sample Image asd model.ImagePath;
Also, I have tried the following line, and it works:
<img src="~/Content/img/sql_error.JPG" alt="Sample Image" width="300px" />
How to display that image from path? Could the image path be different based on settings? Any other ideas?
I don't really get it now on how razor syntax works.
To upload the image, click on Choose File and then browse to the image which you want to upload. Once the image is selected then the name of the image will be displayed next to the Choose File button as shown in the following screenshot. As you can see the that images.
Right-click in the Store Index action method and select Add View as before, select Genre as the Model class, and press the Add button. This tells the Razor view engine that it will be working with a model object that can hold several Genre objects.
In your View try like this
<img src= "@Url.Content(Model.ImagePath)" alt="Image" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With