Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

this is the model.

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:

~/Content/img/sql_error.JPG
~/Content/img/sql_error.JPG
Sample Image asd model.ImagePath;

i also tried:

<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. any other ideas?

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

thanks, Gabriel Sas

share|improve this question

1 Answer

up vote 4 down vote accepted

In your View try like this

  <img src= "@Url.Content(Model.ImagePath)" alt="Image" />
share|improve this answer
works as expected, thanks :) – Sas Gabriel Apr 13 at 11:41
@SasGabriel You're welcome :) – Adithya Apr 13 at 11:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.