0

Within my application I have multiple file locations that hold different types of images. I'm wondering how I should handle these locations within my MVC application?

I want to achieve the following:

  • Make the image locations easily reusable within my MVC application (within views to display and within controllers for image uploads)
  • Make the linking/uploading to the image locations less error-prone
  • Store the locations some how within the application

For example I have the following places within the file system:

  • ~/Content/Images/ImageType1
  • ~/Content/Images/ImageType2
  • ~/Content/Images/ImageType3
  • ~/Content/Images/ImageType4

These are the following options that I've found so far:

  1. Just link to the images within the tags (error-prone)

    eg. <img src="~/Content/Images/ImageType4/{imagefilename}">

  2. Helper method to display each type of image

  3. Creating a route for each image location?

Are there any other ways that I haven't thought of?

Community
  • 1
  • 1
Luke
  • 22,826
  • 31
  • 110
  • 193
  • 1
    I am not sure what is supported out of the box for .NET MVC but as I have seen from other frameworks: https://github.com/liip/LiipImagineBundle . They store in a file or in initialize code a list of types in order to be reusable along with size ,path etc specifications. Of course you might need a helper for your view and a dependency injection or whatever for your controller.Also I suggest direct access to images to avoid routing overhead etc. – GorillaApe Oct 06 '14 at 11:26
  • I hadn't actually considered the routing overhead of using the routing system, maybe just a HTML helper for each image location would suffice for my needs. – Luke Oct 06 '14 at 11:29
  • Here are some ideas http://stackoverflow.com/questions/1149750/using-asp-net-routing-to-serve-static-files – GorillaApe Oct 06 '14 at 11:32

0 Answers0