I recently added jquery references to a project, and now the Post from a View is not triggering. The Post ActionResult saved user-chosen settings, and now a break point inside the Post isn't being hit. There's no error in Visual Studio, but Chrome's Console outputs the warnings "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/." and "Setting 'XMLHttpRequest.withCredentials' for synchronous requests is deprecated."
The code ran before jquery, so is the problem related to those warnings, some other aspect of jquery, or possibly something else? Suggestions here, here, and here offer possible solutions to the asynchronous warnings, but would, say, adding async to the new declarations in the Layout trigger the Post again? Thanks in advance to all.
The View:
@using Project.Data
@model Project.Models.PreferencesModel
@{
ViewBag.Title = "Preferences";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="page_bar clearfix">
<div class="row">
<div class="col-md-8">
<h1 class="page_title">
<i class="fa fa-gears"></i> Preferences
</h1>
</div>
</div>
<div class="page_content">
<div class="container-fluid">
<form data-parsley-validate>
@using (Html.BeginForm("Preferences", "Manage", FormMethod.Post, new { id = "PreferencesForm", autocomplete = "on", data_parsley_validate = "data-parsley-validate" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(m => m.PreferenceID)
@Html.HiddenFor(m => m.PreferenceCreatedBy)
@Html.HiddenFor(m => m.PreferenceCreatedDate)
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="col-md-4">
@Html.LabelFor(m => m.PricingPreferenceTypeID, "Pricing Preference Type")
@Html.DropDownListFor(m => m.PricingPreferenceTypeID, StaticCache.GetPricingPreferenceTypes(), new { @class = "form-control", data_parsley_required = "true" })
@Html.ValidationMessageFor(m => m.PricingPreferenceTypeID)
</div>
<div class="col-md-4">
@Html.LabelFor(m => m.PricingStrategyID, "Pricing Strategy")
@Html.DropDownListFor(m => m.PricingStrategyID, StaticCache.GetPricingStrategies(), new { @class = "form-control", data_parsley_required = "true" })
@Html.ValidationMessageFor(m => m.PricingStrategyID)
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-lg-12 text-right">
<button type="submit" class="btn btn-success btn-large">Save</button>
</div>
</div>
}
</form>
</div>
</div>
The Layout contains these new declarations:
<script src="~/Scripts/jquery-2.1.3.js"></script>
<script src="/Scripts/jquery-ui-1.11.4.js"></script>
Finally, the previously working Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Preferences(PreferencesModel model)
{
ProjectEntities projectDb = new ProjectEntities();
projectDb.uspAddPreference(DateTime.Now, model.PricingStrategyID, null, null, model.PricingPreferenceTypeID);
return RedirectToAction("Preferences");
}
EDIT This piece of jquery was added to the bottom of the View to make one dropdown dependent on the other, but the break point inside the HttpPost ActionResult is still not hit. What could be causing this?
@section Scripts{
<script>
$(function () {
var $dropdownInput = $("#PricingStrategyID");
$("#PricingPreferenceTypeID").change(function () {
if (this.value != 1) {
$dropdownInput.hide();
} else {
$dropdownInput.show();
}
}).change();
});
</script>
}
2nd EDIT
Save button included in original view.