C# 使用ASP.NET MVC时,图像不会显示在视图上

C# 使用ASP.NET MVC时,图像不会显示在视图上,c#,asp.net,json,asp.net-mvc,imagesource,C#,Asp.net,Json,Asp.net Mvc,Imagesource,我试图在web上显示json反序列化后的数据。除了图像之外,所有数据都能正常工作。它在web上只显示图像符号,但现在显示的是实际的图像- public ActionResult PlaceInformation(City objCityModel) { string name = objCityModel.Name; ViewBag.Title = name; var ReadJson = System.IO.File.ReadAllText(Server.MapPath

我试图在web上显示json反序列化后的数据。除了图像之外,所有数据都能正常工作。它在web上只显示图像符号,但现在显示的是实际的图像-

public ActionResult PlaceInformation(City objCityModel)
{
    string name = objCityModel.Name;
    ViewBag.Title = name;
    var ReadJson = System.IO.File.ReadAllText(Server.MapPath(@"~/App_Data/" + name + ".json"));
    RootObject json = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<RootObject>(ReadJson);
    List<Poi> mycities = new List<Poi>();

    foreach (var item in json.poi)
    {
        Poi obj = new Poi()
        {
            Name = item.Name,
            Shorttext = item.Shorttext,
            GeoCoordinates = item.GeoCoordinates,
            Images = item.Images,

        };
        mycities.Add(obj);
    }

    ViewBag.Cities = mycities;
    return View();
}

图像标记将始终期望该图像的路径

<img src="./images/name.jpg" />


图像包含哪些图像路径或图像字节


如果它包含图像字节,则必须通过创建中间页来单独呈现它

将内部循环更改为:

foreach (var image in item.Images) //without the `@`
{
    <img src="@image" />  //with " and />
}
foreach(item.Images中的var image)//不带`@`
{
//使用“and/>
}

如果指定的文件存在,这应该可以工作。(如果不工作,则显示完整错误+html:-)

是如何呈现为html的?我的意思是:输出的html是什么样子的?你在foreach循环中遇到了什么解析器错误?@Stefan。只有符号。不是图像。请发布html输出,
东西。或者,如果甚至没有
,发布它生成的html。检查该元素,看看你得到了什么值ave for src。我使用的是url图像。因此图像直接来自url。您可以右键单击该图像并向我提供正在添加的路径,或者您可以检查正在生成的图像html的视图源吗?我从json文件中获取了所有这些图像。好的,我正在添加关于该问题的json文件。右键单击您的页面和clic我在我的问题中添加了这个视图源代码
  <!DOCTYPE html>

  <html>
  <head>
  <meta name="viewport" content="width=device-width" />
  <title>PlaceInformation</title>
  </head>
  <body>
  <div> 

         <h2>Nordertor</h2>
         <p>The Nordertor is an old town gate in Flensburg, Germany, which was built around 1595. Today the landmark is used as a symbol for Flensburg.</p>
         <p>9.43004861</p>
         <p>54.79541778</p>
            <img src="System.Collections.Generic.List`1[System.String]" />
         <h2>Naval Academy M�rwik</h2>

         <p>9.45944444</p>
         <p>54.815</p>
            <img src="System.Collections.Generic.List`1[System.String]" />
         <h2>Flensburg Firth</h2>


         </p>
         <p>9.42901993</p>
         <p>54.7959404</p>
            <img src="System.Collections.Generic.List`1[System.String]" />


   </div>
   </body>
   </html>
  {
   "poi":[
    {
      "Name": "Nordertor",
      "Shorttext": "The Nordertor is an old tows used as a symbol for Flensburg.",
      "GeoCoordinates": {
        "Longitude": 9.43004861,
        "Latitude": 54.79541778
      },
      "Images": [
        "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6b/Nordertor_im_Schnee_%28Flensburg%2C_Januar_2014%29.JPG/266px-Nordertor_im_Schnee_%28Flensburg%2C_Januar_2014%29.JPG"
      ]
    },
    {
      "Name": "Naval Academy Mürwik",
      "Shorttext": "The Naval Academy Mürwik is the main training e..",
      "GeoCoordinates": {
        "Longitude": 9.45944444,
        "Latitude": 54.815
      },
      "Images": [
        "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/MSM-hauptgebaeude.jpg/400px-MSM-hauptgebaeude.jpg"
      ]
    },

    {
      "Name": "Flensburg Firth",
      "Shorttext": "Flensburg Firth or Flensborg Fjordg and the villages Munkbrarup, Langballig, Westerholz, Quern, Steinberg, Niesgrau, Gelting, and Nieby.\n\n",
      "GeoCoordinates": {
        "Longitude": 9.42901993,
        "Latitude": 54.7959404
      },
      "Images": [
        "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8c/Flensborg_Fjord_ved_bockholmwik.jpg/400px-Flensborg_Fjord_ved_bockholmwik.jpg"
      ]
    }



    ]


}
<img src="./images/name.jpg" />
<img src="http:/wwww.sitename.com/images/name.jpg" />
foreach (var image in item.Images) //without the `@`
{
    <img src="@image" />  //with " and />
}