Reputation: 18099
A simple question (I hope):
We have a set structure within our projects for Assets, that being /Assets/img/, /Assets/css/ and /Assets/js/
I've been reading Brad Wilson's excellent article on Unobtrusive AJAX, in which he mentions the files required, FTA:
In addition to setting the flag, you will also need to include two script files: jQuery (~/Scripts/jquery-1.4.1.js) and the MVC plugin for unobtrusive Ajax with jQuery (~/Scripts/jquery.unobtrusive-ajax.js).
Is anyone aware of a way of informing MVC to look in a folder other than /Scripts/ for these files - I don't want to add a whole folder in the root of the project just for these 2 files.
UPDATE Oh dear, end of the day brain-rot obviously. Sorry all!
Many thanks
Upvotes: 1
Views: 826
Reputation: 19214
the way that I have seen it done is to create an extension method on the HtmlHelper
class for including javascript.
public static string Script(this HtmlHelper helper, string filename)
{
if(!filename.EndsWith(".js")) filename += ".js";
var path = string.Format("<script src='/Assets/js/{0}' type="text/javascript"></script>", filename);
return path;
}
then in your master page you can add this block to the header
<%= Html.Script("jquery-1.4.1") %>
<%= Html.Script("jquery.unobtrusive-ajax.min") %>
Upvotes: 0
Reputation: 57783
In your view, you can use whatever path you want to set up for your scripts:
<script src="@Url.Content("~/Scripts/jquery-1.4.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
I have mine pointed to the Scripts folder as that is what was set up by default, but you can change that to your specific path.
Upvotes: 1