imagine kitty magazine

Skip to main content
  • Categories

    • America
    • ASP.NET
    • Bible tags
    • C#
    • Christianity
    • Classic ASP
    • Firearms
    • Humor
    • LINQ
    • MVC
    • Programming
    • Random
    • Trackbacks
    • Web design
    • Web standards
    • Why I am the way I am
    • Wordpress
  • Links

    • ASP.NET Resources
    • Bible Dude
    • Cake Wrecks
    • Church Communications Pro
    • Creating Passionate Users
    • Dossy’s Blog
    • Gary Turner’s html & css workshop
    • id Projections
    • Information Pollination
    • SystemDotWeb
    • The Crazy Rants of Samantha Burns
    • The Nice Jewish Website
    • The Sneeze
    • Tyssen Design
  • Pages

    • Bible verse tags 2.0
    • Privacy Policy
    • Steps to building a proper web page
  • Info

    • home
    • Log in
    • contact mark
    • blogs that link here*
    • valid xhtml
    • valid css
    • valid rss2
    • rss feed
Sigarms P229

spam this

« Dynamic CSS using ASP.NET MVC
Shoutcast Radio server »

Dynamic Javascript using ASP.NET MVC

  1. Create a new MVC applictaion
  2. Open /Views/Shared/Site.Master
    1. <script src=”/Scripts/script.js” type=”text/javascript”></script>
    2. This doesn’t point to anything yet
  3. Open Global.asax
    1. Add a MapRoute
      1. routes.MapRoute(“Javascript”, “Scripts/{scriptFile}.js”, new { controller = “Scripts”, action = “Index”, scriptFile = “script” });
      2. Now /Scripts/script.js points to Script/Index
  4. Add a view for CssController/Index
    1. <%= Url.Content(“~/Content/test.jpg”) %>
  5. Change contenttype in page directive of Views/Scripts/Index.aspx to “text/javascript”
  6. That should do it.

Adding strongly typed objects to javascript is now simple to achieve and instead of adding javascript to the <head> in your master page you can just have a dynamically generated and cached .js file.

You may download a sample MVC2 project here.

This entry was posted on 15Aug10 @ 1407 and is filed under ASP.NET, C#, MVC, Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a comment

Sponsored links

468x60-1 email address
Google
Custom Search

Amazon Wishlist

Hello, friends! I've decided to put my Amazon wishlist online. If you feel nice today you can purchase one of the items listed and it will be shipped to my door. My birthday is May 13th and I will gladly accept gifts for any Christian or Jewish holiday. Thank you for your support.

Site search and links

I'm a friend of Israel

234x60

Open Trackback Alliance Logo


Widgetize!
WWW is deprecated
no-WWW class B
free email addresses
*blogs that link here powered by Technorati

©2013 imaginekittymagazine