Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a problem with Firefox.
I want to send the selected value of my Dropdown to my Controller.
This code works without any Problems in IE, Edge.

View:



@section myScripts{

@Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">

$("#z").change(function () {
var options = {};
options.url = "/kontierung/changeZeitraum";
options.type = "POST";
options.data = JSON.stringify({ zeitraum: $("#z").val() });
options.dataType = "json";
options.contentType = "application/json";
options.success = function (changeZeitraum) {
$("#z").empty();
};
$.ajax(options);
this.form.submit($("#z").val());
});
<script>
}



@using (Html.BeginForm("Index", "Kontierung")) {

@Html.DropDownList("#z", ViewBag.zeitraum as List<SelectListItem>, new { @id = "z", @class = "form-control", @style = "width: 75px;margin-top:-10px;float:right" })
}

Controller:
public void changeZeitraum(string zeitraum) {
Session["Zeitraum"] = zeitraum;
}

any suggestions to fix it for Firefox?
thanks in advance

What I have tried:

I tried to use Document ready function, put [HttpPost] over the method in controller.
Posted
Updated 3-May-16 2:48am
Comments
Karthik_Mahalingam 3-May-16 4:23am    
what is your expected value and what value you are getting currently?
Member 12196566 3-May-16 8:13am    
The ViewBag.zeitraum is filled with strings
when I set a breakpoint in the controller, this breakpoint is not reached by debugging.
But in IE or Edge it works :/
Ehsan Sajjad 3-May-16 8:11am    
can you check the console for any errors?
Ehsan Sajjad 3-May-16 8:11am    
and put it in document.ready function
Member 12196566 3-May-16 8:24am    
$(document).ready(function () {
$("#z").change(function () {
var x = ($("#z").val());
var options = {};
options.url = "/kontierung/changeZeitraum";
options.type = "POST";
options.data = JSON.stringify({ zeitraum: x });
options.dataType = "json";
options.contentType = "application/json";
options.success = function (changeZeitraum) {
$("#z").empty();
};
$.ajax(options);
this.form.submit($("#z").val());
});
});

is also not working

1 solution

JavaScript
$(document).ready(function () {
           $("#z").change(function () {
               var options = {};
               options.url = "/kontierung/changeZeitraum";
               options.type = "POST";
               options.data = JSON.stringify({ zeitraum: $("#z").val() });
               options.dataType = "json";
               options.contentType = "application/json";
               options.success = function (changeZeitraum) { $("#z").empty(); };
               $.ajax(options);
               this.form.submit($("#z").val());
           });
       });

JavaScript





here is my code in better view
 
Share this answer
 
Comments
F-ES Sitecore 3-May-16 8:54am    
Your code makes no sense, you do an ajax post and then a form submit? Google how to call an MVC action via ajax and go from there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900