Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 传入数据并返回图像?_C#_Html_Asp.net Mvc - Fatal编程技术网

C# 传入数据并返回图像?

C# 传入数据并返回图像?,c#,html,asp.net-mvc,C#,Html,Asp.net Mvc,我使用debug查看返回的HTML: [Authorize] public ActionResult Index(string guid) { OrderSignatureRecord order = _signatureService.GetByGUID(guid); string pathToImage = order.PathToImageFile; var dir = Server.MapPa

我使用debug查看返回的HTML:

   [Authorize]
    public ActionResult Index(string guid)
    {
            OrderSignatureRecord order = _signatureService.GetByGUID(guid);
            string pathToImage = order.PathToImageFile;

            var dir = Server.MapPath("/" + order.PathToImageFile);
            var path = Path.Combine(dir, guid + ".jpg");
            return base.File(path, "image/jpeg");
    }

因此返回了一些内容,但它不使用GUID来搜索正确的内容

有没有关于出了什么问题的想法?
谢谢

您可以通过两种方式完成此操作:

  • 返回文件位置,而不是内容(msdn在您的基础上显示。文件:创建FileContentResult对象)

  • 返回内容并使用此代码(仅建议用于小图像)


  • 尝试返回var路径而不是base.File(我认为您希望返回mime类型的实际文件内容),但您需要文件名。

    您应该尝试返回图像路径(字符串)。尝试了此操作。现在,当iv检查html时,img标记已被删除?例如,当您使用Chrome并查看html标记时,它是否消失了?
       [Authorize]
        public ActionResult Index(string guid)
        {
                OrderSignatureRecord order = _signatureService.GetByGUID(guid);
                string pathToImage = order.PathToImageFile;
    
                var dir = Server.MapPath("/" + order.PathToImageFile);
                var path = Path.Combine(dir, guid + ".jpg");
                return base.File(path, "image/jpeg");
        }
    
     <img src='/OrchardLocal/RainBowProject/ReturnImage' alt="Doorstep signature" style="width:290px;height:290px;" />