asp mvc image reference from resx - asp.net-mvc

I have ASP MVC 4 website.
I use ResX files to localize the site to different languages.
In one of my pages I display localized HTML content (case study) that has images in it.
The whole localized content is stored in a file and the ResX file reference it. This works great.
The problem is how to reference the images from within the localized content?
The images are stored in ~/Content/Img1.jpg (and so on).
For now I've simply put /Content/Img1.jpg but this will not work so good if the website will be deploy to a sub-directory and not the root domain.
Thank you,
Ido.

I think that if you give the same name to the pictures, and this pictures are already embedded in the resources, then you don't have to do anything else, just change the Culture and UICulture as always. If they are different then you might want to see the exact name by inspecting the resources file after compilation. And if your content always references the same static images, it shouldn't be a problem to put the normal path as you always do. The reference that starts with ~ will always start from the root and the structure can be ~Content/en-US/picture1.jpg for example. Let me know if it helps,

Related

Localisation issue

I have set up an MVC4 environment where I have created some localisation using simple resx files in the resources directory. The naming of the file I have used was XXXXX.resx and XXXXX.nl.resx.
This worked brilliantly. I have now changed to a (brilliant) third party application (resxmanager.com) since I expect to use a lot of different languages. This application however, uses the "xx-XX" convention for creating the various language files.
So far, so good. I am able to manage the resource files without any problem. The issue is however, that my application doesn't use the correct resource files. The culture and uiculture indicate that the browser is working in the right (i.e. nl-NL) culture but the proper resources are not selected. I have tried various settings in the web.config ([ui]culture="auto", [ui]culture="xx-XX", [ui]culture="xx" etc) but I'm stuck on what to do next.
Is anyone able to put me into the right direction?

MVC File Structure Standards

I am just new to MVC, we are building a massive system and have alot of namespacing in our site.
Where is the standard place to store files (CSS, Images, .JS) etc?
Would it be good to put them under the Content folder in sub-folders to their namespace or drop them in with their respective parent files or both.
The default project structure includes a Content folder for CSS files and a Scripts folder for JavaScript files. A lot of people use this existing template, especially since a lot of Nuget projects may rely on this.
I personally like to put all of the content in a Content folder, and have a subfolder under this named Css and Scripts. It's really a matter of preference though. Do whatever is consistent and well-organized. That will be the key to making the application more easily maintainable.
Its better to put it in saparate folder as Script(js file) at root level.
Add sub folder in content folder for Images and Css etc.
we can also create multiple controller and views for each section of your project.
like for login section you can add Authentication Controller.
we can also use Helper class for adding general function and use it in every where.
you can see following link
http://msdn.microsoft.com/en-us/library/dd410120(v=vs.100).aspx

MVC Themes, Layouts and CSS

I am creating an MVC application that will effectively allow a user to upload a number of Themes to the site.
Each theme they upload will have a _Layout.cshtml file, along with css files and images.
These will all be stored in locations mapped to the userId of the person creating the uploads, i.e.:
Users/Themes/32-bit-guid/_Layout.cshtml
Users/Themes/32-bit-guid/css
Users/Themes/32-bit-guid/images
The problem I have, is that although the templates are uploaded and I can select any of the templates (which are then applied to the current logged in user), the CSS files are ignored, along with the images.
If I try to browse to the path Users/Themes/32-bit-guid/css/screen.css which I know exists, I get a resource cannot be found error.
I have had a look at creating custom view engines, ignoring routes and everything, but I am getting no where.
Has anyone experienced this before and can they point me in the right direction please?
Views in MVC require a Web.config, all I did to get the themes working was copy the default web.config file from any Views folder and put it in the same directory as my Layout.cshtml

Can I serve images in ASP.NET MVC application from Views directory

I have some pages designed by someone else as simple HTML that I need to dump into my MVC application.
Not surprisingly the images are stored in a local /images directory.
I'd like to be able to serve the images up from the Views directory where the main view pages are.
I'd rather do this than make it its own virtual directory, but I'm not sure if this is really easy or possible. In the future i forsee having to add 'mvc' components (such as RenderPartial or Html extension code) into the pages so I'd prefer the pages to be part of my application instead of just tagging along in their own virtual directory.
Main path:
http://example.com/microsite/
Images path:
http://example.com/microsite/images
I'd want microsite/images to map to Views/Microsite/images if possible.
Or if theres a way to create a 'pseudo' virtual directory in the application I'd rather do that than rely on having to set up the virtual directory from within IIS - but I don't think thats possible.
I tried using something like this, but that doesnt work of course because this isnt actually mapping, but just an ignoring of a route:
routes.IgnoreRoute("microsite/images/{*pathInfo}");
Using <img src="<%=Url.Content("~/my/path/to/images/picture.png")%> should resolve no matter what the actual location of the image. Instead of "~/Content/Images", you'll point to "~/Views/Products/Images/product1.png", or something close to that.
There is no need to modify routes with this implementation.
It sounds like you might benifit from a MVC 2 feature called "Areas". Phil Haack posted on this new feature.

Why not have the Scripts folder inside of the Content folder for ASP.NET MVC project?

Out curiosity I was wondering if there was a logical reason to have the Scripts folder not a sub folder of the Contents folder in an ASP.NET MVC project. The Contents folder typically contains your style sheets and images and for some reason it would seem natural to me to also include the Scripts folder in there as well.
Possibly because scripts could be denoted as providing more functionality than style and design items, so it could be considered a portion of your business logic.
The scripts and content folders are containers for client-side consumed files. They don't affect your MVC applications in any way. You can rename and move them around as you see fit, provided you update the URL references to them to point to the new path.
Having said that, I personally tend to rename these to js and css mostly because this makes my URLs shorter and easier to read and understand.

Resources