Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am working on a project in which I have used angularjs and mvc.I am passing data from angular js controller to my mvc controller by $http.post().For now I am using single object/json array to retreive data like this -public bool UpdateIssueDetails(IssueBO issue).But I want that if I could do like this public public bool UpdateIssueDetails(IssueBO issue,List lstMembersToNotify).I want to send two json arrays from ny angular js controller to my above mvc controller method.

angularjs controller code

 $scope.saveIssueDetails = function (issue) {
    var milestoneId = "";
    var milestoneName = "";
    if ($scope.selectedIssue.Milestone== undefined) {
        milestoneId = "";
        milestoneName = "";
    } else {
        milestoneId = $scope.selectedIssue.Milestone.Id;
        milestoneName = $scope.selectedIssue.Milestone.Name;
    }
    var arrMembersToNotify = [];
    var arrMembersToNotifyNew = [];
    var iCount = 0;
    $("#membersToNotify input[type=checkbox]:checked").each(function () {
        arrMembersToNotify = $(this).val().split("~");
        arrMembersToNotifyNew.push({ "UserId": arrMembersToNotify[0], "UserDisplayName": arrMembersToNotify[1], "Email": arrMembersToNotify[2] });         
    }); 
    var issueDetails =
   {
    Id: issue.Id,
    ProjectId: issue.ProjectId,
    ProjectName: issue.ProjectName,
    IssueStatusId: $scope.selectedIssue.Status.Id,
    StatusName: $scope.selectedIssue.Status.Name,
    IssuePriorityId: $scope.selectedIssue.Priority.Id,
    PriorityName: $scope.selectedIssue.Priority.Name,
    AssignedUserId: $scope.selectedIssue.AssignedTo.Id,
    AssigneeDisplayName: $scope.selectedIssue.AssignedTo.DisplayName,
    IssueCategoryId: $scope.selectedIssue.Category.Id,
    CategoryName: $scope.selectedIssue.Category.Name,
    DueDate: $scope.selectedIssue.DueDate,
    OwnerUserId: $scope.selectedIssue.OwnedBy.Id,
    OwnerDisplayName: $scope.selectedIssue.OwnedBy.DisplayName,
    IssueTypeId: $scope.selectedIssue.Type.Id,
    IssueTypeName: $scope.selectedIssue.Type.Name,
    IssueResolutionId: $scope.selectedIssue.Resolution.Id,
    ResolutionName: $scope.selectedIssue.Resolution.Name,
    MilestoneId: milestoneId,
    MilestoneName: milestoneName,
    Estimation: $scope.selectedIssue.Estimation,
    Progress: $scope.selectedIssue.Progress,
   };
    var url = window.location.protocol + '//' + window.location.host + '/api/Issues' + '/UpdateIssueDetails/';
    $http.post(url, [issueDetails, arrMembersToNotifyNew]).success(function (data, status, headers, config) {
        if (data != '' || data.length >= 0 || data == true) {
            //$scope.selectedIssue = issue;
            //$scope.showIssueDetails($scope.selectedIssue);
            $scope.GetAssignedIssues();
        }
        else if (data == '' || data == false) {
            $scope.selectedIssue = null;
        } else {
            $scope.errors.push(data.error);
        }
    });
};

mvc controller code

  [HttpPost]
    [AuthenticationRequired]
    public bool UpdateIssueDetails(IssueBO issue,List<IssueNotification> lstMembersToNotify)
    {
        try
        {
            //var issueDetails = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(issueAllDetails[0].ToString());
            //List<Dictionary<string, string>> membersToNotifyDetails = JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(issueAllDetails[1].ToString());
            var membersToNotify = lstMembersToNotify.Select(membersToNotifyDetail =>
                                                                new IssueNotification()
                                                                {
                                                                    UserId =membersToNotifyDetail.UserId,
                                                                    Email =
                                                                        membersToNotifyDetail.Email,
                                                                    UserDisplayName =
                                                                        membersToNotifyDetail.UserDisplayName
                                                                }).ToList();
            var newIssue = new IssueBO
            {
                OwnerUserId = issue.OwnerUserId,
                OwnerDisplayName = issue.OwnerDisplayName,
                LastUpdatedUserId = SessionItems.UserId,
                LastUpdaterDisplayName = SessionItems.DisplayName,
                LastUpdatedOn = DateTime.Now,
                ProjectId = issue.ProjectId,
                ProjectName = issue.ProjectName,
                Id = issue.Id,
                AssignedUserId = issue.AssignedUserId,
                AssigneeDisplayName = issue.AssigneeDisplayName,
                IssueStatusId = issue.IssueStatusId,
                StatusName = issue.StatusName,
                Progress = issue.Progress,
                IssuePriorityId = issue.IssuePriorityId,
                PriorityName = issue.PriorityName,
                IssueTypeId = issue.IssueTypeId,
                IssueTypeName = issue.IssueTypeName,
                IssueCategoryId = issue.IssueCategoryId,
                CategoryName = issue.CategoryName,
                IssueResolutionId = issue.IssueResolutionId,
                ResolutionName = issue.ResolutionName,
                DueDate = issue.DueDate,
                Estimation = issue.Estimation,
                MilestoneId = issue.MilestoneId,
                MilestoneName = issue.MilestoneName
            };
            var result = BLL.AdminLayer.UpdateIssueDetail(newIssue, membersToNotify);
            return result.IsSuccessful && result.Result;
        }
        catch (Exception ex)
        {
            BLL.Base.BaseLayer.WriteApplicationLog(ex);
            return false;
        }
    }

I am passing two json array from my angularjs controller like this-$http.post(url, [issueDetails, arrMembersToNotifyNew]).success(function (data, status, headers, config).But I am getting error trying this.Please suggest how to achieve this.Thanks

share|improve this question
    
What the error says? – adricadar Jun 3 '15 at 7:07
    
Failed to load resource: the server responded with a status of 500 (Internal Server Error) – rupinder18 Jun 3 '15 at 7:18

You need to pass data to the action by using JSON.stringify()

$http.post(url, JSON.stringify({ issue: issueDetails, 
     lstMembersToNotify: arrMembersToNotifyNew 
});
share|improve this answer
    
If he stringify's the object, won't he have to deserialize it? In which case, wouldn't sending it as an object be enough? – Sylvan D Ash Jun 3 '15 at 7:17
    
@SylvanDAsh we need to [FromBody] annotation in front of action parameter of controller...that would not lead to do stringify() asp.net/web-api/overview/formats-and-model-binding/… – Pankaj Parkar Jun 3 '15 at 7:20
    
@rupinder18 does it work for you? – Pankaj Parkar Jun 5 '15 at 16:29

Post it as properties of an object.

$http.post(url, { issue: issueDetails, lstMembersToNotify: arrMembersToNotifyNew });
share|improve this answer
    
still not working getting this error-Failed to load resource: the server responded with a status of 500 (Internal Server Error) – rupinder18 Jun 3 '15 at 7:19
    
Debug the asp.net controller method. 500 usually means an exception was thrown on the server. – ChrisV Jun 3 '15 at 7:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.