I have several ASP.NET MVC3 and 4 web sites. All sites are using the same resources that are separate to a library. Resources are .resx files.
I’d like to use images from these resource in my html inside these sites.
I wasn’t using resx files before so not sure what is a good way to work with them.
I think that I might create a service to provide right image from right resource file, but i guess there should be a better way.
My question is what is a good way to use these images from resx files and might be it is not really good to store images in a resx?
I have several ASP.NET MVC3 and 4 web sites. All sites are using the
Share
One easy way to do this is to add a
FileStreamResultaction to the controller, which should return the image based on the resource key.Now you should be able to access it from your view like this:
An alternate way (which can be done using only the view) is to create a base 64 encoded string.
A good way to implement this might be to use a Razor helper, to enable the more straightforward syntax in the view
@Html.GetImageFor(Resources.Images.Image1, "alt").Note: The properties on the .ResX files should be set as follows (as normal for MVC projects):
CustomToolto PublicResXFileCodeGeneratorCustom Tool Namespaceto Resources