【发布时间】:2016-09-29 22:52:36
【问题描述】:
我想从我的 AJAX 中检索 JSON,格式为
{ID_USER : ID_INSTRUCTION}
我的 JSON 结果:
[{"658":"81"},{"658":"82"},{"658":"90"},{"658":"101"}]
这是我用于发布 AJAX 的 jQuery 代码:
$("#boutton-add").on('click',function (e) {
e.preventDefault();
var newFormData = [];
var usr = $('.usr_id').attr('id');
jQuery('.tab_inst tr[name="inst"]').each(function (i) {
var tb = jQuery(this);
var obj = {};
tb.find('button[name="delete"]').each(function () {
obj[usr] = this.id;
});
if (obj[usr] != null)
newFormData.push(obj);
});
var jsonresult = JSON.stringify(newFormData); // object return instruction of user after removing and adding informations
//alert(jsonresult);
//----------------------ajax to posting json to actionresult
$.ajax({
type: 'POST',
url: '/Usr_Inst/set_user_inst/',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: jsonresult,
traditional: true,
success: function (data) {
alert(jsonresult);
}
});
});
现在一切正常。
现在我想从包含两列 ID_USER 和 ID_INSTRUCTION 的 USER_INSTRUCTION 表中添加或删除程序,为此我需要一个具有参数 IEnumerable <USER_INSTRUCTION> 的 ActionResult 方法。
public ActionResult set_user_inst(IEnumerable<USER_INSTRUCTION> jsonresult)
{
// adding or removing programs.
}
我的模型类是这样的:
[Table("DPH.USER_INSTRUCTION")]
public partial class USER_INSTRUCTION
{
[Key]
public decimal ID_USER { get; set; }
public decimal ID_INSTRUCTION { get; set; }
public virtual INSTRUCTION INSTRUCTION { get; set; }
public virtual USERS USER { get; set; } }
项目运行时我从 MVC 控制器参数中得到的值是ID_USER = 0 an ID INSTRUCTION = 0
【问题讨论】:
-
您应该将相关代码发布到问题中!不是某些图片的链接!。
-
这里不要放截图,放代码
-
值得注意的是requests for urgency do not go down well here - 请阅读
:-)。 -
对于
Some HELP Please !!!!,即使在我写了关于请求紧急的说明之后,我还是投了反对票。我们对这里的要求反应不佳。 -
好的,谢谢你的评论!
标签: jquery asp.net json ajax asp.net-mvc