简体   繁体   English

控制器不接收从json.stringify(obj)传递的值

[英]Controller do not receive values passed from json.stringify(obj)

I am not understand this case: 我不了解这种情况:

I have a model like: 我有一个像这样的模型

public class ExmDescobertos {
    public int Id { get; set; }
    public int ExameId { get; set; }
    public int PlanoId { get; set; }
    public int ConvenioId { get; set; }
}

And create an object javascript : 并创建一个对象javascript

var objDescoberto = new Object();
objDescoberto.Id = $("#hdnDescobertoId").val(); //inputs with values...
objDescoberto.ExameId = $('#hdnExameId').val();
objDescoberto.PlanoId = $('#hdnPlanoId').val();
objDescoberto.ConvenioId = $('#hdnConvenioId').val();

And I am using Json.stringify(obj) to transmit the values with a $.post jQuery method: 我正在使用Json.stringify(obj)通过$ .post jQuery方法传输值:

var dados = JSON.stringify(objDescoberto);

In this point, dados is "{"Id":"27","ExameId":"53","PlanoId":"32","ConvenioId":"11"}" , for example. 在这一点上, dados例如“ {” Id“:” 27“,” ExameId“:” 53“,” PlanoId“:” 32“,” ConvenioId“:” 11“}”

And have a controller with this action: 并让控制器执行以下操作:

public PartialViewResult(ExmDescobertos descoberto) { }

But... the parameter in this controller not receive your values correct! 但是...此控制器中的参数无法正确接收您的值! :o In this point descoberto is Id = 0; :o在这一点上descobertoId = 0; ExameId = 0; ExameId = 0; PlanoId = 0; PlanoId = 0; ConvenioId = 0; ConvenioId = 0;

Not errors explicit, but not works... Anybody have a idea of what I have missing? 没有明确的错误,但没有用...任何人都知道我缺少了什么? Thank you for all! 感谢你所做的一切!

Don't stringify you object, just send object as is. 不要对您的对象进行stringify ,只需按原样发送对象即可。

$.post("/url", objDescoberto);

or 要么

var dados = JSON.stringify({descoberto : objDescoberto});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM