无法从ajax发布电话发送json字典

时间:2014-05-15 02:18:09

标签: javascript ajax json asp.net-mvc-4 dictionary

我正在使用MVC 4.0应用程序,我需要使用JSON数据(AJAX POST)发送Dictionary调用。我能够发送/传递正常数据,但我的问题是我无法发送dictionary数据。

请看下面的图片(能够传递正常参数,例如:TemporaryId

enter image description here

请看下面的图片(不能从javascript传递字典,例如:_mappedValuesenter image description here

我的AJAX电话如下:

$.ajax({
        url: 'api/projects/Advanced',
        type: 'POST',
        dataType: 'json',
        data: {
            'TemporaryId': tempId,
            'Name': projectName,
            'InputFileType': 19,
            'Mapping': {
                'Keys': ['Latitude', 'Longitude', 'PoleId', 'Description', 'Street'],
                'Values': [values[1],values[2],values[3],values[4],values[5]],                   
                'MappedValues': {
                    'Latitude': selectedMapping[0],
                    'Longitude': selectedMapping[1],
                    'PoleId': selectedMapping[2],
                    'Description': selectedMapping[3],
                    'Street': selectedMapping[4]
                },
                'MandatoryColumns': ['Latitude', 'Longitude'],
                'OptionalColumns': ['PoleId', 'Description', 'Street']
            },
            'IsActualProjectCreatedOrUpdated': false,
            'IsSaveProject': true,
            'ProjectId': null
        },
        async: false,
        cache: false,
        success: function (data) {
        },

我的业务逻辑如下:

控制器:

    [HttpPost]
    [ActionName("Advanced")]
    public HttpResponseMessage VerifyAndSaveProject([FromBody] ProjectCreationUpdationResult project)
    {
        var result = _projectProcess.ValidateAndSaveProject(project);
    }

课程:ProjectCreationUpdationResult

public class ProjectCreationUpdationResult
{
    /// <summary>
    /// Id of project
    /// </summary>
    public int? TemporaryId { get; set; }

    /// <summary>
    /// Name of the project
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    /// Type of the input file
    /// </summary>
    public int InputFileType { get; set; }  

    public ExcelColumnMapping Mapping { get; set; }

    public bool IsActualProjectCreatedOrUpdated { get; set; }
    public bool IsSaveProject { get; set; }

    /// <summary>
    /// Id of project
    /// </summary>
    public int? ProjectId { get; set; }
}

课程:ExcelColumnMapping

public class ExcelColumnMapping
{
    private readonly List<string> _keys;
    private readonly List<string> _mandatoryColumns;
    private readonly List<string> _optionalColumns;
    private readonly List<string> _values;
    private readonly Dictionary<string, string> _mappedValues;

    //here properties
    ------------------
}

0 个答案:

没有答案