How to display an image from a path in asp.net MVC 4 and Razor view?

前端 未结 4 1379
天命终不由人
天命终不由人 2020-11-30 02:15

I have the following model:

public class Player
{


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


        
相关标签:
4条回答
  • 2020-11-30 02:42

    you can also try with this answer :

     <img src="~/Content/img/@Html.DisplayFor(model =>model.ImagePath)" style="height:200px;width:200px;"/>
    
    0 讨论(0)
  • 2020-11-30 02:44

    Try this ,

    <img src= "@Url.Content(Model.ImagePath)" alt="Sample Image" style="height:50px;width:100px;"/>
    
    (or)
    
    <img src="~/Content/img/@Url.Content(model =>model.ImagePath)" style="height:50px;width:100px;"/>
    
    0 讨论(0)
  • 2020-11-30 02:57
     @foreach (var m in Model)
        {
          <img src="~/Images/@m.Url" style="overflow: hidden; position: relative; width:200px; height:200px;" />
        }
    
    0 讨论(0)
  • 2020-11-30 03:03

    In your View try like this

      <img src= "@Url.Content(Model.ImagePath)" alt="Image" />
    
    0 讨论(0)
提交回复
热议问题