Asp.net core mvc 未根据abp.ajax请求将数据发送到服务器

Asp.net core mvc 未根据abp.ajax请求将数据发送到服务器,asp.net-core-mvc,aspnetboilerplate,Asp.net Core Mvc,Aspnetboilerplate,我正在使用ASP.NET样板文件模板。我在让服务器接收我从abp.ajax post请求发送的数据时遇到问题(代码如下所示) 控制台正在记录正确的数据(如屏幕截图1所示),但服务器没有返回正确的数据。当我调试时,id为1000的数据在服务器上显示为0,即使console记录了1000,这就是发送的对象 截图1: 截图2: Jquery: $(document).on('click', '.default-customer-selection', function (e) {

我正在使用ASP.NET样板文件模板。我在让服务器接收我从abp.ajax post请求发送的数据时遇到问题(代码如下所示)

控制台正在记录正确的数据(如屏幕截图1所示),但服务器没有返回正确的数据。当我调试时,id为1000的数据在服务器上显示为0,即使console记录了1000,这就是发送的对象

截图1:

截图2:

Jquery:

$(document).on('click', '.default-customer-selection', function (e) {
        e.preventDefault();

        var info = {
            toCustomerId: 1000 //Just trying to keep this simple for now
        };

        console.log(info);

        abp.ajax({
            url: abp.appPath + 'Portal/Catalog/SwitchCustomer',
            data: JSON.stringify(info),
            success: function (data) {
              console.log('Data Returned: ' + data.personId);
            }
        });
    });
交换机客户的型号/数据输入:

using System;
using System.Collections.Generic;
using System.Text;

namespace MySolution.Catalog.Dtos
{
    public class SwitchCustomerInput
    {
        public long ToCustomerId { get; set; }
    }
}
我的控制器功能:

public class CatalogController : MySolutionControllerBase
{ 
    [HttpPost]
    public JsonResult SwitchCustomer(SwitchCustomerInput input)
    {
        return Json(new { PersonId = input.ToCustomerId });
    }
}
我正在遵循指南和我在项目中看到的其他在解决方案中已经正常工作的预构建示例:


我漏了一步吗?非常感谢您的帮助

ajax将选项作为对象获取。您可以传递jQuery的$.ajax方法中有效的任何参数。这里有一些默认值:数据类型是“json”,类型是“POST”,内容类型是“application/json”(因此,在发送到服务器之前,您可以调用json.stringify将javascript对象转换为json字符串)

您需要向操作的参数添加
[FromBody]
属性,如下所示:

[HttpPost]
public JsonResult SwitchCustomer([FromBody]SwitchCustomerInput input)
{
      return Json(new { PersonId = input.ToCustomerId });
}