jquery - 将数据数组从 Json 传递给 wcf 函数作为参数

标签 jquery asp.net ajax wcf json

大家好,我正在使用 json 在 wcf 服务中传递数据。下面是我的代码。我能够传递数据ProjectCollection

但我想像这样将数据作为数组传递

var ProjectCollection = ['new','test','etc'];

var ProjectCollection = "Test";      
  function GetEmployee() {
        Type = "GET";
        Url = "http://localhost:52136/Service1.svc/GetTimesheetEntries";
        DataType = "jsonp";
        Data = {vb: ProjectCollection,vb1: '1'};
        ProcessData = false;
        method = "GetTimesheetEntries";
        CallService();
    }

 function CallService() {
        $.ajax({
            type: Type, //GET or POST or PUT or DELETE verb
            url: Url, // Location of the service
            data: Data, //Data sent to server
            contentType: ContentType, // content type sent to server
            dataType: DataType, //Expected data format from server
            processdata: ProcessData, //True or False
            success: function (msg) {//On Successfull service call
                ServiceSucceeded(msg);
            },
            error: ServiceFailed// When Service call fails
        });
    }

这是我的网络服务功能。所以我的要求是将所有数组数据从 json 获取到这个函数参数。

 public List<WcfService1.Customer> GetTimesheetEntries(string[] vb , string vb1)
    {
        DataClasses1DataContext i = new DataClasses1DataContext();
        //var b = from vb in i.TimeSheetMasters select vb;
        //return b.ToList();

        var list = from time in i.TimeSheetMasters
                   join activity in i.ProjectMasters
                   on time.ProjectId equals activity.ProjectId
                   join res in i.ResourceMasters on time.ResourceId equals res.ResourceId
                   where time.TaskDetails == vb && time.BookHours == vb1
                   select new WcfService1.Customer
                   {
                       RName = res.ResourceName,
                       PName = activity.ProjectTitle
                   };

        return list.ToList();


    }

最佳答案

我找到了解决方案

  function GetTimeSheet() {
    //webserviceurl[2]
    Type = "GET";
    Url = "http://gtsp12:3030/Service1.svc/GetTimesheetEntries";
    DataType = "jsonp";
    Data = { Projects: JSON.stringify(projectlist), Resources: JSON.stringify(Resourcelist) };
    method = "GetTimesheetEntries";
    CallService1();
}

只需在脚本中创建数组即可。像上面一样初始化它并作为 webservice 中的参数传递。

关于jquery - 将数据数组从 Json 传递给 wcf 函数作为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8353130/

相关文章:

javascript - Bootstrap datepicker 日期范围结束日期更新

jquery - MathJax:尝试重新呈现数学时无法从给定数据进行回调

javascript - Chrome 中无法刷新父窗口

javascript - 跨浏览器问题: firefox does not load images from a php file after first load

AJAX跨域图片发布到WCF服务

php - ' "turns out as\' 和\"

jquery - jQuery 对话框中的元素未绑定(bind)到 Post 上的 ViewModel

JavaScript - 如果禁用复选框,则使用 jQuery 添加类

asp.net - 为什么我使用 c# 在 asp.net 中收到来自 Paypal 的无效响应?

c# - 回发后页面客户端验证问题