Pass image from controller and display in a view using ViewBag in ASP.NET MVC 3

后端 未结 4 1859
無奈伤痛
無奈伤痛 2021-01-18 01:57

I guess it\'s something very straight forward but I can\'t find out how to do it. In my controller I have:

 public ViewResult ShowForm()
        {
                   


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 02:29

    You need a ImageController to render that.

    See this:

    ASP.NET MVC3: Image loading through controller

    and this: Can an ASP.NET MVC controller return an Image?

    once you have a controller you can render as follows:

    public class ImageController{
    
    public ActionResult ShowImage(string path) 
    {
    
        return File(path);
    }
    
    }
    

    in your views:

    
    

提交回复
热议问题