【问题标题】:pass simple json array from ios to C# mvc web service将简单的 json 数组从 ios 传递到 C# mvc web 服务
【发布时间】:2014-09-30 20:00:54
【问题描述】:

我使用以下代码将 json 数组从 ios 传递到 C# mvc 代码。 但是总是说到txtName为null

你能解释一下哪里错了吗?

-- C#控制器代码

[HttpPost]

    public ActionResult SampleText(string[] txtName)

{
  return Json(txtName);
}

--ios代码

(void)receiveOnAnotherThreadTestingArray:(id)sender {




        NSURL *wsUrl = [NSURL URLWithString:strContactURL];
        AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:wsUrl];


     NSMutableArray *ukMakes = [NSMutableArray arrayWithObjects:@"google",@"yahoo",@"fb",
                                  nil];

        NSDictionary *dcParams222 = [NSDictionary dictionaryWithObjectsAndKeys:
                                     ukMakes, @"txtName",


                                     nil];


        NSMutableURLRequest *afRequest = [httpClient requestWithMethod:@"POST" path:strContactURL parameters:dcParams222];

        [afRequest setTimeoutInterval:5.0];

        AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:afRequest success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
                                             {

                                             }
                                                                                            failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON)
                                             {

                                    }];

        [operation start];


}

任何帮助表示感谢..

【问题讨论】:

  • 你确定 SampleText 真的被调用了吗?因为您在 actionresult 上方使用了 HttpPost 属性。我不确定这是否能解决任何问题,但是当我对我的 actionresult 进行 ajax 调用时,我需要指定允许从 get 请求中调用 json。返回 Json(txtName, JsonRequestBehavior.AllowGet););

标签: c# ios asp.net-mvc json


【解决方案1】:

我不确切知道参数是如何传递给您的控制器操作的(我不太熟悉 Objective-c),但公认的答案可能值得探索

How do I accept an array as an ASP.NET MVC controller action parameter?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    相关资源
    最近更新 更多