ASP.NET MVC image from byte array

前端 未结 2 1642
一整个雨季
一整个雨季 2020-12-14 02:31

currently I have a byte array representing my Image in my ViewModel. I display it with the following code:



        
2条回答
  •  猫巷女王i
    2020-12-14 02:58

    You could define a controller action that will serve the image:

    public class ImagesController: Controller
    {
        public ActionResult Index(int id)
        {
            byte[] imageData = ... go get your image data from the id
            return File(imageData, "image/png"); // Might need to adjust the content type based on your actual image type
        }
    }
    

    and in your view simply point the src property of the img tag to this controller action:

    
    

提交回复
热议问题