C# 将javascript模型传递给控制器
我想不出我在这里遗漏了什么。我在这里构建了一个javascript模型,它是它的一个简化版本。有人知道为什么我的模型没有和数据一起传递给我的控制器吗 正在构建的Javascript模型:(这确实正确填充) Ajax调用: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
$.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();
}
});