user3128303
user3128303

Reputation: 747

Specific piece of jQuery doesn't work

The script displays a Test11 so loaded properly. Unfortunately, Test22 no longer has displayed. Anyone know what might be causing this?

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")
    }))
{
    <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>
}

@Scripts.Render("~/bundles/jquery")
<script src="@Url.Content("~/Scripts/first_file.js")"></script>

Script first_file.js,

$(function () {

    $('#FormatsID').change(function () {
        alert('Test11');
        var URL = $('#someID').data('oneAction');
        $.getJSON(URL + '/' + $('#FormatsID').val(), function (data) {
            alert('Test22');
        });
    });
});

Browser console,

console

Upvotes: 0

Views: 35

Answers (2)

Muhammad Saifullah
Muhammad Saifullah

Reputation: 4292

Try this

new
{
    id = "someID",
    data_oneAction = '@Url.Action("one")'
}))

var URL = $('#someID').prop('data_oneAction');

Upvotes: 1

Andre Pena
Andre Pena

Reputation: 59336

This piece of code:

var URL = $('#someID').data('oneAction');

Is returning undefined, because it should be:

var URL = $('#someID').attr('data-oneAction');

Upvotes: 2

Related Questions