Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将数据收集对象从jQueryAjax方法传递到MVC控制器,显示空对象_Javascript_Jquery_Ajax_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

Javascript 将数据收集对象从jQueryAjax方法传递到MVC控制器,显示空对象

Javascript 将数据收集对象从jQueryAjax方法传递到MVC控制器,显示空对象,javascript,jquery,ajax,asp.net-mvc,asp.net-mvc-4,Javascript,Jquery,Ajax,Asp.net Mvc,Asp.net Mvc 4,我尝试使用JQuery方法将数据对象传递给MVC控制器。当我单击submit按钮时,它将在JavaScript方法中创建数据对象。Ajax方法中的数据对象不为null。当我们将它传递给MVC控制器时,它正确地命中了该方法,但数据对象显示为null 我也尝试了单个对象,但它也显示为null 这是JQuery Ajax方法: $(function () { $('.save-user').on('click', function () { var tr = $(this).

我尝试使用JQuery方法将数据对象传递给MVC控制器。当我单击submit按钮时,它将在JavaScript方法中创建数据对象。Ajax方法中的数据对象不为null。当我们将它传递给MVC控制器时,它正确地命中了该方法,但数据对象显示为null

我也尝试了单个对象,但它也显示为null

这是JQuery Ajax方法:

$(function () {
    $('.save-user').on('click', function () {

        var tr = $(this).parents('tr:first');
        var SrcCountryId = $("#ExchangeRateSetUpHeader_SrcCountryId option:selected").val();
        var DestCountryId = $("#ExchangeRateSetUpHeader_DestCountryId option:selected").val();
        var SrcCurrencyId = $("#ExchangeRateSetUpHeader_SrcCurrencyId option:selected").val();
        var DestCurrencyId = $("#ExchangeRateSetUpHeader_DestCurrencyId option:selected").val();
        var Rate = $("#ExchangeRateSetUpHeader_Rate").val();
        var RemittanceSettlementId = tr.find("#RemittanceId").val();
        var CommPercentage = tr.find("#CommPercentage").val();
        var CommFixed = tr.find("#CommFixed").val();
        var SellRate = tr.find("#SellRate").val();
        var Id = tr.find("#ItemId").val();

        var ExchangeRateSetUp =
            {
                "Id": Id,
                "SrcCountryId": SrcCountryId,
                "DestCountryId": DestCountryId,
                "SrcCurrencyId": SrcCurrencyId,
                "DestCurrencyId": DestCurrencyId,
                "Rate": Rate,
                "RemittanceSettlementId": RemittanceSettlementId,
                "CommPercentage": CommPercentage,
                "CommFixed": CommFixed,
                "SellRate": SellRate
            };
        $.ajax({
            url: '/ExchangeRateSetUp/Create/',
            type: 'POST',
            data: JSON.stringify(ExchangeRateSetUp),
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                alert(data);
            }
        });
        });
        });
这是我的MVC控制器方法

[HttpPost]
public JsonResult Create(ExchangeRateSetUp model)
{
   return Json("Success", JsonRequestBehavior.AllowGet);
}
请帮我整理一下这个问题。
谢谢。

您正在以
json
string的形式传递数据,因此您需要在
create
方法中将其作为string接受

在create方法中将
ExchangeRateSetUp
对象更改为
String
参数,然后将
String
转换为
ExchangeRateSetUp
对象:

public JsonResult Create(String model)
{
   //convert String model into ExchangeRateSetUp here

   return Json("Success", JsonRequestBehavior.AllowGet);
}

同样的事情也发生在我身上。原因是c#类中没有{get;set;}定义为在控制器中接受模型


检查您的类ExchangeRateSetUp是否具有{get;set;}属性

您在哪里从ajax调用创建方法?我称为“url:”/ExchangeRateSetUp/create/“脚本方法的底部,您能显示ExchangeRateSetUp模型代码吗?