Asp.net mvc Draw2d C#MVC将JSON发布到控制器

Asp.net mvc Draw2d C#MVC将JSON发布到控制器,asp.net-mvc,json,draw2d,draw2d-js,Asp.net Mvc,Json,Draw2d,Draw2d Js,我正在使用Draw2D库,它允许导出JSON,但当我尝试这样做时,我无法将它导出到MVC。这不是Draw2D的问题,而是我缺乏关于如何使其工作的知识。 我生成了如下所示的JSON [ { "type": "DBTable", "id": "662b1fb8-5eb8-47a5-9f81-e48efb0d31bd", "x": 80, "y": 59, "width": 99, "hei

我正在使用Draw2D库,它允许导出JSON,但当我尝试这样做时,我无法将它导出到MVC。这不是Draw2D的问题,而是我缺乏关于如何使其工作的知识。 我生成了如下所示的JSON

    [
    {
        "type": "DBTable",
        "id": "662b1fb8-5eb8-47a5-9f81-e48efb0d31bd",
        "x": 80,
        "y": 59,
        "width": 99,
        "height": 107,
        "cssClass": "DBTable",
        "bgColor": "#DBDDDE",
        "color": "#D7D7D7",
        "stroke": 1,
        "alpha": 1,
        "radius": 3,
        "name": "Default AutoAttendant",
        "entities": [
            {
                "text": "0",
                "id": "0c4c5414-1f35-4247-a4b7-38297aa0e5ff"
            },
            {
                "text": "1",
                "id": "706e1cb7-a9d1-461d-8230-0bf136c1d850"
            }
        ]
    },
    {
        "type": "NamedUser",
        "name": "Scott",
        "id": "0d2c71cf-52ee-4c50-a974-ea07003df05e",
        "cssClass": "NamedUser",
        "bgColor": "#DBDDDE",
        "color": "#D7D7D7",
        "stroke": 1,
        "alpha": 1,
        "radius": 3,
        "x": 220,
        "y": 200
    },
    {
        "type": "NamedUser",
        "name": "Nancy",
        "id": "601b0ad9-a0e9-4604-8861-38694a43e0a8",
        "cssClass": "NamedUser",
        "bgColor": "#DBDDDE",
        "color": "#D7D7D7",
        "stroke": 1,
        "alpha": 1,
        "radius": 3,
        "x": 220,
        "y": 200
    }
]
我的控制器目前非常基本,可以消除所有潜在的副作用问题

public ActionResult Draw2dRetrieveJSON(AllJson AllJsontxt)
    {
我的班级看起来像这样

public class AllJson
{
   public  IEnumerable<HostedVoiceUserJson> HostedVoiceUserJson { get; set; }
   //public IEnumerable<HostedVoiceHuntGroupJson> HostedVoiceHuntGroupJson { get; set; }
   //public IEnumerable<HostedVoiceAAJson> HostedVoiceAAJson { get; set; }
   //public IEnumerable<HostedVoiceConnectionJSON> HostedVoiceConnectionJSON { get; set; }
}

当然,我不能一直坐在这里手动更改这些,我需要能够找到其他方法来让它工作,这样我就可以将多个不同的类型放在一起

看起来您的JSON是一个对象数组。为了让ModelBinder自动识别,您需要均质JSON集合


根据类型,您可以分离JSON对象并将它们发送到不同的同构数组中。通过这种方式,你可以在C#

中匹配你的模型类,我找到了一个解决方法,但这只是一个解决方法,它正好解决了我当前的问题,但因为这个问题是一个更广泛的问题,我想如果能得到比我现在拥有的更彻底的解决方案,对很多人都有好处,我会让这个问题继续下去。就我的解决方案而言,我创建了一个新类,它包含了我所有类的所有属性,在控制器中之后,我将它们从控制器中分离出来。不是最优的,但目前有效。
{
                "HostedVoiceUserJson": [
                    {
                        "type": "NamedUser",
                        "name": "Scott",
                        "id": "0d2c71cf-52ee-4c50-a974-ea07003df05e",
                        "cssClass": "NamedUser",
                        "bgColor": "#DBDDDE",
                        "color": "#D7D7D7",
                        "stroke": 1,
                        "alpha": 1,
                        "radius": 3,
                        "x": 220,
                        "y": 200
                    },
                    {
                        "type": "NamedUser",
                        "name": "Nancy",
                        "id": "601b0ad9-a0e9-4604-8861-38694a43e0a8",
                        "cssClass": "NamedUser",
                        "bgColor": "#DBDDDE",
                        "color": "#D7D7D7",
                        "stroke": 1,
                        "alpha": 1,
                        "radius": 3,
                        "x": 220,
                        "y": 200
                    }
                ]
            }