Checking if file exists in asp.net mvc 4

Total Post:3

Points:21
 483  View(s)
Ratings:
Rate this:

I want to check the existence of image ... how to do this can anyone help me..

 @if (Server.MapPath("~/Content/Images/UserImage/" +Model.ID + ".png"))

                {
                    <img src="~/Content/Images/UserImage/" + @Model.ID + ".png" alt="@Model.FirstName">
                }

Thanks..

  1. Post:10

    Points:70
    Re: Checking if file exists in asp.net mvc 4

    Try this am sure this will solve your problem 

     @if (File.Exists(Server.MapPath("~/Content/Images/UserImage/" + Model..ID + ".png")))
                    {
                        <img src="~/Content/Images/UserImage/" + @userDetails.ID + ".png" alt="@Model.FirstName">
                    }
    

                  

Answer