Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4040652
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:46:46+00:00 2026-05-20T12:46:46+00:00

I have a asp.net mvc project. in a speicific views i call the four

  • 0

I have a asp.net mvc project. in a speicific views i call the four image from different different folder inside my proect.

sometime image can not be found. i want to set a image for every folder because all 4 folder contain different diffent size of image so i need to set the image of specific size for each folder.

how i can show the default image when the image not found any way to do that.i means call the none.png when the directory not have image who i called in the views.

are their any way to show the image in the case of image not found.

any way to do that in asp.net 4 MVC 3. using web.config or setting anything else.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:46:47+00:00Added an answer on May 20, 2026 at 12:46 pm

    Easiest way to do this is with a html helper. Please be mindful of the extra performace hit of checking the file system before even showing an image filename. The hit is a small one though, so you won’t notice any issues unless you are getting very high traffic. Then you can implement some sort of caching so the app “knows” if the file exists or not.

    You can use a custom html helper for it

    public static class ImageHtmlHelpers
    {
       public static string ImageUrlFor(this HtmlHelper helper, string contentUrl)
       {
           // Put some caching logic here if you want it to perform better
           UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
           if (!File.Exists(helper.ViewContext.HttpContext.Server.MapPath(contentUrl)))
           {
               return urlHelper.Content("~/content/images/none.png");
           }
           else
           {
               return urlHelper.Content(contentUrl);
           }
       }
    }
    

    Then in your view you can just make the url using:

    <img src="<% Html.ImageUrlFor("~/content/images/myfolder/myimage.jpg"); %>" />
    

    EDIT: As Jim pointed out, I haven’t really addressed the sizing issue. Personally I use automatic size request management/size which is a whole other story, but if you are concerned about the folders/sizes simply pass that information in to build the path. As below:

    public static class ImageHtmlHelpers
    {
       public static string ImageUrlFor(this HtmlHelper helper, string imageFilename, ImageSizeFolderEnum imageSizeFolder)
       {
           UrlHelper urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
           string contentUrl = String.Format("~/content/userimages/{0}/{1}", imageSizeFolder, imageFilename);
           if (!File.Exists(helper.ViewContext.HttpContext.Server.MapPath(contentUrl)))
           {
               return urlHelper.Content(String.Format("~/content/userimages/{0}/none.png", imageSizeFolder));
           }
           else
           {
               return urlHelper.Content(contentUrl);
           }
       }
    }
    

    Then in your view you can just make the url using:

    <img src="<% Html.ImageUrlFor("myimage.jpg", ImageSizeFolderEnum.Small); %>" />
    

    Have suggested an Enum for better programmatic control if the folder is a fixed set, but for a quick and nasty approach, not reason why you can’t just use a string if the folder is db generated etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Asp.net MVC project that modestly uses jQuery scripts. My views also
I have an asp.net mvc project, and a function that streams out an image
I have ASP.Net MVC project. Plus wordpress blog under a subfolder /Blog. Now, when
I have an ASP.NET MVC project with xVal and data annotations and I need
We have an ASP.Net MVC project that will start with a single web server
I have a ASP.NET MVC 4 project and a SQL View (vvItem). ItemController MVCAppEntities
I have a new asp.net mvc project and i am trying to figure out
In Visual Studio 2010 I have an ASP.NET MVC 3 project called blahblah. As
I have asp.net mvc 4 web application project on my server in IIS Directory.
In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.