Click here to Skip to main content
14,882,025 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
this is the model.
C#
public class Player
    {


        public String ImagePath
        {
            get
            {
                return "~/Content/img/sql_error.JPG";
            }

        }


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:
CSS
~/Content/img/sql_error.JPG
~/Content/img/sql_error.JPG
Sample Image asd model.ImagePath;


i also tried:
XML
<img src="~/Content/img/sql_error.JPG" alt="Sample Image" width="300px" />
and this works


how to display that image from path?
the model image path can be different, based on settings.

i don't really get it now on how razor syntax works.

thanks,
Gabriel Sas
Posted
Updated 1-Jan-18 22:27pm
v3

this is the solution :)
<img src="@Url.Content(Model.ImagePath)" alt="Image" />
   
C#
<pre><pre lang="Javascript">
ang="java">
   
<img src= "@Url.Content(Model.ImagePath)" alt="Sample Image" style="height:50px;width:100px;"/><br />
<br />
(or)<br />
<br />
<img src="~/Content/img/@Url.Content(model =>model.ImagePath)" style="height:50px;width:100px;"/>
   
Comments
Member 13050931 24-Oct-18 8:45am
   
My Problem is, I am having Images ~/Area/Checks/Images. Unable to display that images on the web page which is in Area (MVC 4).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900