In my last refactoring post I demonstrated using the MVCContrib helper extension Html.ScriptInclude to help tidy up jscript files.

This time I'll show you a another MVCContrib helper Html.Stylesheet.  As the name suggests it works in the same way as ScriptInclude but works for css stylesheets.

The key to this helper method is sticking with a convention of storing your css files in Content\Css:

image

Now in your master file use the following:

   1:  <head runat="server">
   2:      <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
   3:      
   4:      <%= Html.Stylesheet("Site.css") %>
   5:      <%= Html.Stylesheet("jquery.cluetip.css")%>
   6:      
   7:      <%= Html.ScriptInclude("Jquery-1.3.2.js") %>
   8:      <%= Html.ScriptInclude("Jquery-validate.js") %>
   9:      <%= Html.ScriptInclude("Jquery-metadata.js") %>
  10:      <%= Html.ScriptInclude("Jquery-cluetip.js") %>
  11:      <%= Html.ScriptInclude("Jquery-example.js") %>
  12:      <%= Html.ScriptInclude("jquery-ui-1.7.2.custom.min.js")%>
  13:      <%= Html.ScriptInclude("Form.Common.OnLoad.js") %>
  14:      <asp:ContentPlaceHolder ID="HeadContent" runat="server" />
  15:  </head>

Now that looks much better!


Posted in: ASP.NET MVC  Tags: , ,

Comments


July 22. 2009 13:50
trackback
ASP.NET MVC Refactoring CSS Includes With Helper Methods

You've been kicked (a good thing) - Trackback from DotNetKicks.com

http://www.dotnetkicks.com/mvc/ASP_NET_MVC_Refactoring_CSS_Includes_With_Helper_Methodshttp://www.dotnetkicks.com/mvc/ASP_NET_MVC_Refactoring_CSS_Includes_With_Helper_Methods


July 22. 2009 20:45
Brett Slaski
So what happens if you leave the css files in the /content directory, will they not be found?  I assume the same for the scripts?

http://blog.brettski.com/http://blog.brettski.com/


July 22. 2009 23:50
trackback
Dan Gibbons - ASP.NET MVC Refactoring CSS Includes With Helper Methods

DotNetBurner - burning hot .net content

http://dotnetburner.com/detail/845/dan-gibbons-aspnet-mvc-refactoring-css-includes-with-helper-methodshttp://dotnetburner.com/detail/845/dan-gibbons-aspnet-mvc-refactoring-css-includes-with-helper-methods


July 24. 2009 11:11
James Radford
Good stuff Smile

http://www.jamesradford.net/http://www.jamesradford.net/


July 30. 2009 00:07
Admin
Sorry Brett, missed comment that's right if the scripts/css files are in the correct directory then the helpers won't find them.

http://www.ifunky.net/http://www.ifunky.net/

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

«  March 2010  »
MoTuWeThFrSaSu
22232425262728
1234567
891011121314
15161718192021
22232425262728
2930311234
View posts in large calendar

Authors

Recent Comments

Banners

Theme Grabber
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010 Dan Gibbons .Net Developer