无法使用ajax调用在javascript中以点表示法发布数据。 [英] Not able post data in dot notation in javascript using the ajax call.

查看:57
本文介绍了无法使用ajax调用在javascript中以点表示法发布数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过ajax发送json数据... 

var JSONobj = {
组: FisrtGroup,员工:[
{EmpId: 1,FullName: Doe},
{EmpId: 4 ,FullName: Jones}]
}; iam发送请求时

..其发送数据如 ...

组: FirstGroup
员工[ 0 ] [EmpId]: 1
员工[ 0 ] [FullName]: Doe
员工[ 1 ] [EmpId]: 2
员工[ 1 ] [FullName]: Jones

无法绑定ASP.NET MVC模型上的员工数据
因此我需要像这样发送使用未编入索引的点符号..

组: FirstGr oup
员工[ 0 ]。EmpId: 1
员工[ 0 ]。FullName: Doe
员工[ 1 ]。EmpId: 2
员工[ 1 ]。FullName:< span class =code-string> Jones

此结构自动绑定到模型 asp.net mvc





我有什么尝试过:



我试图使用包含对象集合(员工)的对象发送数据,但没有任何帮助。任何建议。

解决方案

上课。



公共类JSONobj

{

公开string group {get; set;}

public List< employees> {get; set;} //员工类列表

}



然后将此类对象作为参数传递给WebMethod。


尝试使用字段的双引号。

  var  JSONobj = { 
FisrtGroup 员工: [
{ EmpId 1 FullName Doe},
{ EmpId 4 FullName 琼斯}]
};





对于数字,你可以忽略1中的引号4


Iam sending the json data through ajax...

    var JSONobj = {
        Group: "FisrtGroup", Employees: [
    { EmpId: "1", FullName: "Doe" },
    { EmpId: "4", FullName: "Jones" }]
    };

when iam sending the request.. its sending data like this...

Group: "FirstGroup"
Employees[0][EmpId] : "1"
Employees[0][FullName] : "Doe"
Employees[1][EmpId] : "2"
Employees[1][FullName] : "Jones"

which not able to bind employees data on ASP.NET MVC Model 
Hence I need to send like this using the dot notation not indexed based..

Group: "FirstGroup"
Employees[0].EmpId : "1"
Employees[0].FullName : "Doe"
Employees[1].EmpId : "2"
Employees[1].FullName : "Jones"

This structure is auto binded to Models in asp.net mvc 



What I have tried:

I have tried to send the the data using the object containing the collection of objects(employee) but nothing helped..any suggestions.

解决方案

Make a class.

Public Class JSONobj
{
public string Group{get;set;}
public List<employees> {get;set;}//List of Employees class
}

Then pass this class object as argument in your WebMethod.


Try with double quotes for fields.

var JSONobj = {
"Group": "FisrtGroup", "Employees": [
{ "EmpId": "1", "FullName": "Doe" },
{ "EmpId": "4", "FullName": "Jones" }]
};



For numbers, you can ignore the quotes in "1" and "4"


这篇关于无法使用ajax调用在javascript中以点表示法发布数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆