开发者

What files should go in the ASP.NET MVC Content folder?

开发者 https://www.devze.com 2023-03-15 07:52 出处:网络
I see that ASP.NET MVC generates a Content folder by default, which stores the site.css file. I have a site that uses some image files and XML files in order to do its job, yet I do not want to have t

I see that ASP.NET MVC generates a Content folder by default, which stores the site.css file. I have a site that uses some image files and XML files in order to do its job, yet I do not want to have those files as embedded 开发者_JAVA百科resources. Should I just put the files in the solution within the content folder? Should I turn off the "Do not copy" build option on each resource since I will need to deploy the files to the website? Or should these files not even live in the solution and be loaded from the file system?


It's a good approach to add all your files/resources to the solution (at least you can see them in VS ;-) Other developers won't be surprised that your solution really needs some other files.

If those files are the 'content' of your website (like css files) then you can store them in the Content folder. It is up to you what folder structure you come up with. For example you might want to store your images in folder related to the modules of your application, or just all in the images folder. MVC doesn't enforce any particular way of keeping your resource files.

Just leave the Build Action set to Content and Copy to Output Directory to 'Do not copy'.

You might want to take a look at T4MVC project (also available as NuGet package) which will help you in keeping urls to your images / files compile-time safe.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号