【发布时间】: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