One of the conventions within the ASP.NET MVC framework is store JavaScript files in the Scripts directory, nothing wrong with this and when you reference your scripts you probably do something like:

<script type="text/javascript" src="/scripts/FormHelpers.js"></script>

If you’re not using MVC Contrib in your applications then download it now! 

 http://www.codeplex.com/MVCContrib

Once you reference the MVC Contrib assemblies you’ll have access to lots of goodies one of which relating to this post is the html helper extension Html.ScriptInclude.  Using this helper refactors the output by removing duplication and encapsulating the script location into one place.

   1: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   2:  
   3: <html xmlns="http://www.w3.org/1999/xhtml">
   4: <head runat="server">
   5:     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
   6:        
   7:     <%= Html.ScriptInclude("Jquery.js") %>
   8:     <%= Html.ScriptInclude("Form.Helpers.js") %>
   9:     <%= Html.ScriptInclude("Form.Common.OnLoad.js") %>%>
  10:     
  11:     <asp:ContentPlaceHolder ID="head" runat="server">
  12:     </asp:ContentPlaceHolder>    
  13: </head>
  14:  

Comments


June 4. 2009 19:33
trackback
ASP.NET MVC Refactoring JavaScript Includes With Helper Methods

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

http://www.dotnetkicks.com/aspnet/ASP_NET_MVC_Refactoring_JavaScript_Includes_With_Helper_Methodshttp://www.dotnetkicks.com/aspnet/ASP_NET_MVC_Refactoring_JavaScript_Includes_With_Helper_Methods


June 5. 2009 10:27
trackback
Daily Tech Links - June 5, 2009

Daily Tech Links - June 5, 2009 Web Development ASP.NET MVC Refactoring JavaScript Includes With Helper

http://weblogs.asp.net/sanjeevagarwal/archive/2009/06/04/daily-tech-links-june-5-2009.aspxhttp://weblogs.asp.net/sanjeevagarwal/archive/2009/06/04/daily-tech-links-june-5-2009.aspx

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading



Calendar

«  February 2010  »
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567
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