简体   繁体   English

将简单的json数组从ios传递到C#mvc Web服务

[英]pass simple json array from ios to C# mvc web service

I have used the following code for pass json array from ios to C# mvc code. 我已经使用以下代码将json数组从ios传递到C#mvc代码。 but always comes to the txtName is null 但总是出现txtName为null

could you please explain where is the wrong?? 你能解释哪里错了吗?

-- C# controller code -C#控制器代码

[HttpPost] [HttpPost]

    public ActionResult SampleText(string[] txtName)

{
  return Json(txtName);
}

-- ios code -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];


}

any help appreciate.. 任何帮助赞赏..

I don't know exactly how the parameters are being passed to your controller action (I'm not really familiar with objective-c) but the accepted answer might be worth exploring 我不确切知道如何将参数传递给您的控制器操作(我对Objective-c并不很熟悉),但是可以接受的答案可能值得探讨

How do I accept an array as an ASP.NET MVC controller action parameter? 如何接受数组作为ASP.NET MVC控制器操作参数?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM