John
John

Reputation: 3945

pass in data and return an image?

<img src='@Url.Action("Index", "ReturnImage", new { guid = @Model.GUID })' alt="Doorstep signature" style="width:290px;height:290px;" />

With the above line of code I am trying to access ReturnImageController and pass @Model.GUID to the Index function....where it should return an image:

   [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");
    }

ive used debug to see what HTML is returned:

 <img src='/OrchardLocal/RainBowProject/ReturnImage' alt="Doorstep signature" style="width:290px;height:290px;" />

So something is returned but it doesnt use GUID to search for the proper one.

Any ideas as to what is going wrong? thanks

Upvotes: 0

Views: 136

Answers (2)

Leon
Leon

Reputation: 919

Try to return the var path not the base.File (I think you want to return the actual file content with mime-type), but you need the file name.

Upvotes: 0

Patrick Hofman
Patrick Hofman

Reputation: 156948

You can do this in two ways:

  1. Return the file location, not the content (msdn says on your base.File: Creates a FileContentResult object);

  2. Return the content and use this code (only recommended for small images)

<img src="data:image/png;base64,@Url.Action("Index", "ReturnImage", new { guid = @Model.GUID })" />

Upvotes: 1

Related Questions