3

I am trying to use this answer from an old post: Display image from database in asp mvc
which is:

public class ImageController
{
    public ActionResult Show( int id )
    {
        var imageData = ...get bytes from database...

        return File( imageData, "image/jpg" );
    }
}

and I'm getting the following error:

'System.IO.File' is a 'type' but is used like a 'variable'

This is what I'm using:

using System;
using System.IO;
using System.Drawing.Imaging;
using System.Web.Mvc;

What am I missing?

Community
  • 1
  • 1
user990635
  • 3,979
  • 13
  • 45
  • 66

2 Answers2

4

Make sure that your ImageController derives from Controller which is where the File method is defined:

public class ImageController: Controller
{
    public ActionResult Show( int id )
    {
        var imageData = ...get bytes from database...
        return File( imageData, "image/jpg" );
    }
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

Remove using System.IO if not required. otherwise you may use

return base.File( imageData, "image/jpg" );

OR

return System.Web.Mvc.Controller.File( imageData, "image/jpg" );
Abdul Munim
  • 18,869
  • 8
  • 52
  • 61