jQuery Mobile Cascading Dropdown Not Working After Post

jQuery Mobile Cascading Dropdown Not Working After Post

Looking for some help...I'm using ASP MVC3 and jQuery Mobile. I've built a set of cascading dropdown select lists which work fine when you first open the page. However, after the form is submitted, it returns back to this page so the user can enter more info if needed. The problem is the cascading dropdown no longer works after you are brought back to the page.

I don't see any errors in the console when debugging in Firebug. I have to do a Control + F5 refresh for them to start working again. If I turn off the jQuery mobile ajaxEnabled setting, then it works fine, so it's something to do with the jQuery mobile framework and loading the page I think...

Anyone have any ideas?

Thanks

EDIT: Below is the view for this page. Basically what is happening is the $('#GasStation').change event never seems to fire after the user is brought back to this page. If I disable the jQuery mobile ajax feature, it works fine.

  1. @model CPMobile.Models.FuelUsageModels.CreateModel
  2. @{
  3.     Layout = "~/Views/Shared/M/_Layout.cshtml";
  4. }
  5. <h2>@ViewBag.Title</h2>
  6. <div data-theme="b">
  7.     @Html.ValidationSummary(true, "Fuel usage recording failed. Please correct the errors and try again.")
  8.     <div data-role="fieldcontain">
  9.         @using (Html.BeginForm())
  10.         {
  11.             <div data-role="fieldcontain">
  12.                 @Html.LabelFor(m => m.GasStation)
  13.                 @Html.DropDownListFor(m => m.GasStation, Model.GasStationList, "Select Gas Station...")<br />
  14.                 @Html.ValidationMessageFor(m => m.GasStation)
  15.             </div>
  16.             <div data-role="fieldcontain">
  17.                 @Html.LabelFor(m => m.FuelType)
  18.                 @Html.DropDownListFor(m => m.FuelType, Enumerable.Empty<SelectListItem>(), "Select Fuel Type...")<br />
  19.                 @Html.ValidationMessageFor(m => m.FuelType)
  20.             </div>            
  21.             <div data-role="fieldcontain">
  22.                 @Html.LabelFor(m => m.EquipmentNumber)
  23.                 @Html.TextBoxFor(m => m.EquipmentNumber, new { @required = "required" })<br />
  24.                 @Html.ValidationMessageFor(m => m.EquipmentNumber)
  25.             </div>
  26.             <div data-role="fieldcontain">
  27.                 @Html.LabelFor(m => m.MeasurementValue)
  28.                 @Html.TextBoxFor(m => m.MeasurementValue, new { @required = "required", @type = "number" })<br />
  29.                 @Html.ValidationMessageFor(m => m.MeasurementValue)
  30.             </div>           
  31.             <div data-role="fieldcontain">
  32.                 @Html.LabelFor(m => m.MeasurementDatetime)
  33.                 @Html.EditorFor(m => m.MeasurementDatetime, new { @required = "required", @type = "date" })<br />
  34.                 @Html.ValidationMessageFor(m => m.MeasurementDatetime)
  35.             </div>            


  36.             <div data-role="fieldcontain">
  37.                 <input type="submit" value="Submit" data-theme="b" />
  38.             </div>

  39.         }
  40.     </div>
  41. </div>
  42. @section scripts
  43. {
  44.     <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
  45.     <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
  46.     <script type="text/javascript">        
  47.         $('#GasStation').change(function () {
  48.             var selectedGasStation = $(this).val();
  49.             if (selectedGasStation != null && selectedGasStation != '') {
  50.                 $.getJSON(
  51.                     '@Url.Action("FuelType")',
  52.                     { gasStation: selectedGasStation },
  53.                     function (fuelTypes) {
  54.                         var fuelTypesSelect = $('#FuelType');
  55.                         fuelTypesSelect.empty();

  56.                         $.each(fuelTypes, function (fuelType, fuelTypeName) {
  57.                             fuelTypesSelect.append($('<option/>', {
  58.                                 value: fuelType.value,
  59.                                 text: fuelTypeName.text
  60.                             }));
  61.                         });
  62.                         fuelTypesSelect.selectmenu('refresh', true);
  63.                     });
  64.                 }
  65.             });
  66.     </script>
  67. }