I'm trying to load the scripts for my application. Do not work so I checked a simple alert ('test11');. It also does not work, the script is not loaded at all?
It uses standard _Layout of MVC4 generated by Visual Studio 2013.
View Details.cshtml
@model xzy.Models.Album
@{
ViewBag.Title = "Details";
}
<h2>Details</h2>
@using (Html.BeginForm("Details", "Store", FormMethod.Post,
new
{
id = "someID",
data_oneAction = @Url.Action("one"),
data_twoAction = @Url.Action("two")
}))
{
<fieldset
<label for="Formats">Select format</label>
@Html.DropDownList("Formats", ViewBag.Formats as SelectList,
new { id = "FormatsID", @class = "xxx" })
<input type="submit" value="Submit" id="SubmitID" } />
</fieldset>
}
<script src="@Url.Content("~/Scripts/first_file.js")"></script>
<script src="@Url.Content("~/Scripts/second_file.js")"></script>
Script first_file.js
$(function () {
$('#FormatsID').change(function () {
alert('Test11');
});
});
UPDATE
Yaakov Ellis, it works. But when I have a script with the update, then it not works.
$(function () {
$('#FormatsID').change(function () {
alert('Test11');
var URL = $('#someID').data('oneAction');
$.getJSON(URL + '/' + $('#FormatsID').val(), function (data) {
alert('Test22');
});
});
});
@Scripts.Render("~/bundles/jquery")before the<script src ...then it works.#FormatsID, what errors if any come up in the console logs, what you get when you set javascript breakpoints and step through the code, etc.