ASP. net mvc Best Practices (2)

Source: Internet
Author: User

Address: http://space.itpub.net/740297/viewspace-588774

 

2. create an extension method for urlhelper to map your JavaScript, stylesheet, and image folders to ASP by default. net MVC creates content and scripts folders to store them, but I do not like this method. I like the following folder organization method, which allows me to set static file caching for only one assets folder, instead of Multiple folders: assets + Images + scripts + stylesheets no matter how folders are organized, create the urlhelper Extension Method to map these folders so that you can easily reference them in the view, and, in the future, if you need to modify the folder structure, you do not have to do a lot of "Search/Replace ". We recommend that you create extension methods for resources that are frequently referenced in your view .. Example: 1. Public static string image (this urlhelper helper, string filename) 2. {3. Return helper. Content ("~ /Assets/images/{0} ". formatwith (filename); 4. } 5. 6. Public static string stylesheet (this urlhelper helper, string filename) 7. {8. Return helper. Content ("~ /Assets/stylesheets/{0} ". formatwith (filename); 9. } 10. 11. Public static string noicon (this urlhelper helper) 12. {13. Return image (helper, "noicon.png"); 14. } When referencing these resources, you can reference them as follows: 1. <Link href = "<% = URL. stylesheet (" site.css ") %>" rel = "stylesheet" type = "text/CSS"/> instead of the default one: 1. <Link href = "http://www.cnblogs.com/Content/Site.css" rel = "stylesheet" type = "text/CSS"/>

Related reading:

    • ASP. net mvc unleashed (5) (continued)(Geez, 2009-3-13)
    • ASP. net mvc unleashed (6)(Geez, 2009-3-17)
    • ASP. net mvc 1.0 officially released(Geez, 2009-3-18)
    • ASP. net mvc unleashed (6) (continued)(Geez, 2009-3-21)
    • ASP. net mvc technology topics(Zhu Xianzhong, 2009-3-27)
    • Action filter for ASP. net mvc notes (idotnetspace)
    • ASP. net mvc: analyze the tempdata mechanism (idotnetspace)
    • ASP. net mvc Futures: MVC control Overview (geez, 2009-4-09)
    • ASP. net mvc Futures: local view(Geez, 2009-4-10)
    • ASP. net mvc best practices (1)(Geez, 2009-4-10)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.