Monday, June 25, 2012

How to set Reference for javascript/css file in ASP.NET MVC

When i work with MVC i don't know how to add the js and css files to application.I just give the reference for the files as per asp.net.But it is not a right method to give the reference in MVC.While adding a java script ,css or images are any file which we refer using the source tag "src" we need to use the following syntax in MVC using Asp.net
For java script:

<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.datepicker.addevents.js")"></script>

For Css files:
<link href="@Url.Content("~/csslib/reset.css" rel="stylesheet")" type="text/css" />
<link href="@Url.Content("~/csslib/styles.css" rel="stylesheet")" type="text/css" />

No comments:

Bel