locked
how to check the file result is null within the mvc view RRS feed

  • Question

  • Hi there

    I have a controller method as below to send an image to a MVC view to display

      

    public FileResult ShowImage(GuidID)

    {

    DataServiceClient client = new DataServiceClient ();

     AdviserImage result;

    result = client.GetAdviserImage(ID);

     

    return File(result.Image, "image/jpg"  );

    }


     

    in my view I am using

     

    <img src="<%= Url.Action("ShowImage", "Adviser", new { ID = Model.AdviserID }) %>" alt="<%: Model.LicenceNumber %>" />

     

    to display the image

    but some ids does not have a image and returning null, I want to check the file result is null withing the view and if its null not not to display the image.

     

     

    Help on this much appriciated.

    Thanks

     

     
    Thursday, August 18, 2011 9:55 PM

All replies

  • Could you perhaps put logic in your controller method to first check if no image was returned for the Advisor and if so, send a default image?  Like a transparent GIF or PNG image or something.  At least then you can control what's displayed instead of getting an ugly red X. 


    Tom Overton
    Friday, August 19, 2011 7:33 PM