本文介绍了Json.stringify无法在Firefox中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我的Firefox有问题。

我想将我的Dropdown的选定值发送到我的控制器。

此代码在IE,Edge中没有任何问题。



查看:







@section myScripts {



@ Scripts.Render(〜/ bundles / jqueryval )

< script type =text / javascript>



$(#z)。change(function(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})

}



控制器:

public void changeZeitraum(string zeitraum){

Session [Zeitraum] = zeitraum;

}



任何修复Firefox的建议?

提前感谢



我尝试了什么:



我试图使用Document ready函数,将[HttpPost]放在上面控制器中的方法。

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.

推荐答案




这篇关于Json.stringify无法在Firefox中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 05:41