Please see my other MVC articles.
Instantiating Script and Style References Efficiently
Including references to script and style tags has always been a tedious and time-consuming web development task.
Now MVC 4 provides an alternate method by allowing developers to “bundle” files together into a single reference which may then be referenced to “render” them into appropriate pages.
For this example I’ll begin with a simple table encapsulated within a div.
I wish to style the table and div using style sheets and include a JavaScript file reference.
Instead of using separate include statements, I can “bundle” them together and simply use the virtual reference later within pages.
Now I may refer to each file by its virtual reference (the first string) instead of the much longer file path.
For example, within the Index View I will instruct the MVC engine to generate necessary link and script statements for my style sheets and JavaScript files respectively.
Now within my page’s source, my files have the necessary tags to be used.
When I load my View, I’m presented with proof my JavaScript file is loaded.
Also, my View’s div and table are styled as intended.