如何从AngularJS的post请求发送一个字符串数组到ODataController的action方法? [英] How to send an array of strings to an action method of ODataController from post request by AngularJS?

查看:128
本文介绍了如何从AngularJS的post请求发送一个字符串数组到ODataController的action方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Angular代码低于

 var data = ['  asdfgh''  fghjkl''  qwerty']; 
return $ http.post(url,JSON.stringify(data))。then(function(result){
return result.data;
});



我的web api控制器是

< pre lang =sql> public 类V1MessageController:ODataController
{
[AuthorizeClaims(ClaimTypes.NameIdentifier
[System.Diagnostics。 CodeAnalysis.SuppressMessage( Microsoft.Performance CA1804:RemoveUnusedLocals,MessageId = messageId ,Justification = 测试),HttpPost]
public IHttpActionResult MarkAsReadMessages(ODataActionParameters odataParameters)
{
// Code for implementation
}
}



如果我传递一个简单的字符串,而不是一个数组的字符串到相同的控制器方法与不同的参数,它工作正常。

  public  IHttpActionResult MarkAsReadMessages(Guid  key 
{
//代码用于实现
}



唯一的问题是数组字符串.I我无法将一个数组字符串传递给那个特定的action方法。我认为这是与ODataController类型类成员的角度兼容性问题。请任何人帮助我。我很震惊这个问题,无法弄清楚是什么事先做好。

解决方案

http.post(url,JSON.stringify(data))。then(function(result){
return result.data;
});



我的网络API控制器是

  public 类V1MessageController:ODataController 
{
[AuthorizeClaims(ClaimTypes.NameIdentifier
) [System.Diagnostics.C odeAnalysis.SuppressMessage( Microsoft.Performance CA1804:RemoveUnusedLocals,MessageId = messageId ,Justification = 测试),HttpPost]
public IHttpActionResult MarkAsReadMessages(ODataActionParameters odataParameters)
{
//代码 实现
}
}



如果我传递一个简单的字符串,而不是使用不同参数的相同控制器方法的数组字符串,它工作正常。

  public  IHttpActionResult MarkAsReadMessages(Guid  key 
{
//代码用于实现
}



唯一的问题是数组字符串.I我无法将一个数组字符串传递给那个特定的action方法。我认为这是与ODataController类型类成员的角度兼容性问题。请任何人帮助我。我很震惊这个问题,无法弄清楚是什么做下一步。提前做好,


My Angular code goes below

var data=['asdfgh','fghjkl','qwerty'];
return $http.post(url, JSON.stringify(data)).then(function (result) {
            return result.data;
        });


My web api controller is

public class V1MessageController : ODataController
{
[AuthorizeClaims(ClaimTypes.NameIdentifier
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",           "CA1804:RemoveUnusedLocals", MessageId = "messageId", Justification = "Test"), HttpPost]
public IHttpActionResult MarkAsReadMessages(ODataActionParameters odataParameters)
  {
     //Code for implementation
  }
}


If i am passing a simple string,instead of a string of array to same controller method with different parameter it is working fine.

public IHttpActionResult MarkAsReadMessages(Guid key)
  {
     //Code for implementation
  }


Only problem is with string of array.I am unable to pass a string of array to that particular action method.I think this is a compatibility issue of angular with that of ODataController type class member.Please anybody help me out.I am struck with this problem,not able to figure out what to do next.Thanx in advance,

解决方案

http.post(url, JSON.stringify(data)).then(function (result) { return result.data; });


My web api controller is

public class V1MessageController : ODataController
{
[AuthorizeClaims(ClaimTypes.NameIdentifier
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",           "CA1804:RemoveUnusedLocals", MessageId = "messageId", Justification = "Test"), HttpPost]
public IHttpActionResult MarkAsReadMessages(ODataActionParameters odataParameters)
  {
     //Code for implementation
  }
}


If i am passing a simple string,instead of a string of array to same controller method with different parameter it is working fine.

public IHttpActionResult MarkAsReadMessages(Guid key)
  {
     //Code for implementation
  }


Only problem is with string of array.I am unable to pass a string of array to that particular action method.I think this is a compatibility issue of angular with that of ODataController type class member.Please anybody help me out.I am struck with this problem,not able to figure out what to do next.Thanx in advance,


这篇关于如何从AngularJS的post请求发送一个字符串数组到ODataController的action方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆