Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将javascript模型传递给控制器_C#_Jquery_Asp.net_Ajax_Asp.net Mvc - Fatal编程技术网

C# 将javascript模型传递给控制器

C# 将javascript模型传递给控制器,c#,jquery,asp.net,ajax,asp.net-mvc,C#,Jquery,Asp.net,Ajax,Asp.net Mvc,我想不出我在这里遗漏了什么。我在这里构建了一个javascript模型,它是它的一个简化版本。有人知道为什么我的模型没有和数据一起传递给我的控制器吗 正在构建的Javascript模型:(这确实正确填充) Ajax调用: $.ajax( { context: this, type: 'post', url: '/Threshold/EditThreshold/', data: { model: myModel }, success: function (r

我想不出我在这里遗漏了什么。我在这里构建了一个javascript模型,它是它的一个简化版本。有人知道为什么我的模型没有和数据一起传递给我的控制器吗

正在构建的Javascript模型:(这确实正确填充)

Ajax调用:

$.ajax(
{
    context: this,
    type: 'post',
    url: '/Threshold/EditThreshold/',
    data: { model: myModel },
    success: function (result) {
        //do stuff
    },
    error: function () {
        error();
    }
});
每当在控制器上点击操作时,模型都是空的

签名如下:

[HttpPost]
public JsonResult EditThreshold(ThresholdDetail model)
{
    //Do Stuff
}

不要将
myModel
包装在带有
model
属性的外部对象中(除非最终绑定到的viewmodel以相同的方式设置,这似乎不太可能):

$.ajax({
背景:这,,
键入:“post”,
url:“/Threshold/EditThreshold/”,

数据:myModel,//成功了,谢谢!!,非常接近,但目前为止
[HttpPost]
public JsonResult EditThreshold(ThresholdDetail model)
{
    //Do Stuff
}
$.ajax({
    context: this,
    type: 'post',
    url: '/Threshold/EditThreshold/',
    data: myModel, // <-------
    success: function (result) {
        //do stuff
    },
    error: function () {
        error();
    }
});