Thursday, May 2, 2013

Link CSS and Script Files in ASP.NET MVC 2

To resolve the correct file path in MVC 2 you need to use URL.Content.

Linking a CSS file.

<link href="<%= Url.Content("~/Content/StyleSheet1.css") %>" rel="stylesheet" type="text/css"/>

Linking a JavaScript file.

<script src="<%= Url.Content("~/Content/TreeMenu.js") %>" type="text/javascript"></script>

Adding Images through CSS.

.myClass  { background-image:url(<%: Url.Content("~/Content/icons/page.png")%>); }

No comments:
Write comments
Recommended Posts × +