0

I have used the following code for pass json array from ios to C# mvc code. but always comes to the txtName is null

could you please explain where is the wrong??

-- C# controller code

[HttpPost]

    public ActionResult SampleText(string[] txtName)

{
  return Json(txtName);
}

-- ios code

(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..

Dinithe Pieris
  • 1,822
  • 3
  • 32
  • 44
  • Are you sure SampleText actually gets called? Because you used the HttpPost attribute above the actionresult. I'm not sure if this solves anything but when i do an ajax call to my actionresult i need to specify that the json is allowed to be called from get requests. return Json(txtName, JsonRequestBehavior.AllowGet);); – Jamie Sep 30 '14 at 08:59

1 Answers1

0

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

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

Community
  • 1
  • 1
dtyrrell
  • 31
  • 2