Unable to attach numerous parameters to the content of the request

I am encountering an issue with my code where I have two classes and need to call two separate models using two store procedures to insert data into both tables. The controller is set up like this:

[HttpPost]
public IHttpActionResult AddData([FromBody]IList<Details> details, [FromBody] Request request)
{
    var changeRequestResponse = db.sp_AddChangeRequests(request.EmpID, request.CreatedDate, request.Status).SingleOrDefault();
    GenericResponse objResponse = null;
    foreach (Details detail in details)
    {
        var data = JsonConvert.SerializeObject(db.sp_AddChangeRequestDetails(detail.CRID, detail.Category, detail.Info, detail.Col, detail.Reason).SingleOrDefault(), Formatting.Indented, settings);
        objResponse = JsonConvert.DeserializeObject<GenericResponse>(data);

    }
    return Ok(objResponse);

}

My controller js file looks like this:

$scope.SubmitRequestForm = function(){            
    console.log($scope.changeReqCol);
    var req = {
        method: 'POST',
        url: WebApiUrl + 'AddData',
        headers: {
            'Content-Type': 'application/json'
        },
        data: JSON.stringify($scope.changeReqCol)
    }
    console.log()
    $http(req).then(function (data, status) {
        console.log(data);
    }, function (err, status) {
        console.log(err);
    });
};

When attempting to submit the data, I am experiencing the error mentioned above. Can someone please assist me in identifying what may be missing?

Answer №1

According to information found at this particular source:

A cautionary note is given about using [FromBody] on multiple parameters within the same action method. The request stream is consumed by an input formatter upon first read, rendering it inaccessible for binding additional [FromBody] parameters.

Answer №2

Explore the wonders of using the jQuery POST method to set your data in key-value pairs.

function checkRiderAppID() {

$.post("/url ", {
Params: value
},
function (data, status) {
if (status === 'success') {

} else {
//logic for unsuccessful status
}
});
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering an error in AngularJS $http calls while trying to loop: TypeError - object is not functioning

Currently, I am in the process of automating the population of my app's database with Dummy Data to eliminate the manual task of adding users, friends, and more. To achieve this, I have implemented nested AngularJS $http requests that interact with my ...

When using Next JS with StoryBook, an error may occur if styles are written in a module.scss file

Every time I try to add some styles to my ButtonWidget.scss file, I encounter an error in the console when running the command yarn storybook Error Code: ERROR in ./src/components/ButtonWidget/ButtonWidget.module.scss 1:0 Module parse failed: Unexpected ...

Unable to retrieve the image

When trying to fetch an image, I encountered the following error: Failed to load resource: the server responded with a status of 404 (Not Found) TopBar.jsx import { useContext } from "react"; import { Link } from "react-router-dom"; ...

Looking for a way to assign the object value to ng-model within a select tag from an array of objects? Also, curious about how to easily implement filters on ng-options?

Here is the HTML code for creating a question template: <body ng-controller="myCtrl"> {{loadDataSubject('${subjectList}')}} {{loadDataTopic('${topicList}')}} <h1 class = "bg-success" style="color: red;text-align: ...

Older versions of Android, specifically Android 7 or lower, seem to encounter issues with Apis in React Native when utilizing axios. Fortunately, this problem doesn

For fetching the data, I utilized the 'axios' library. Surprisingly, it works flawlessly on newer Android devices (specifically Android 9 and 10). However, when it comes to older devices like Android 7 or earlier, a persistent Network Error occur ...

Showing a loading animation inside an HTML element

I have a main webpage that contains several buttons. Each button, when clicked, loads a specific target page as an object within a div on the main page. The "target" refers to the page that will be displayed within the object. <script> .... chec ...

Error message: When initiating AJAX requests in ASP.NET, the function is not defined for undefined

I recently followed a tutorial on creating AJAX requests for CRUD operations in an AngularJS application. However, upon trying to perform an AJAX request to retrieve data from the database, I encountered the following error when launching my application: ...

Display hierarchical JSON data in an Angular table

I'm attempting to display nested data from JSON in a table, but I'm having trouble achieving success. My JSON data:- $scope.data = [ { "$id": "1", "Folder": [ { "Name": "Windows-Desktop", "CPU": "2", ...

Obtaining a single pixel from an Image within a Windows Store App using C#

Currently, I am developing a Windows 8 game in C# and facing a challenge with checking the color of a specific pixel within an Image. Despite having the coordinates (x, y) of the pixel, I am unable to find a suitable class that can perform this task. It se ...

Text below a stationary header

I need some help with my code using material-ui-next beta.30. The issue I am facing is that the content within mui.Paper is appearing behind the AppBar instead of below it. Here's my current setup: import * as React from 'react'; import * a ...

Repeating every 3 to 6 months on later.js commencing from a specified date

Currently, I am working on setting up recurring events every 3 and 6 months using the later.js library which can be found at https://github.com/bunkat/later. The code implementation looks like this: // Assuming my value.scheduled_date is set to 2018-09-0 ...

Tips for enabling the OnLoad Event for a React Widget

Hey there! I'm a beginner with React and I'm struggling to call a function once after the component is created. I tried adding an onLoad event in the component creation, but it's not working as expected. The function 'handleClick' ...

Using ng-class to insert variable strings for dynamic styling

I'm currently working on a project where JSON data is used to generate custom forms. I've encountered an issue while trying to add validation to text inputs in the rendered forms. It seems simple enough, but I'm struggling with correctly ren ...

Is there a conventional method for implementing role-based access control for files in Angular?

I have built 4 projects in Angular that grant access to different roles. The dashboard consists of various content pages, with the initial page being the dashboard when a user logs in. The content displayed on the dashboard is determined by the logged-in ...

What specific version is indicated by the @next tag for npm packages?

Which version of the foo package will be installed by running this command? npm install foo@next Neither the package.json nor the semver documentation make reference to the use of next. ...

Why does the 401 error continue to persist while attempting to log in using Google Identity service on my Laravel application?

Trying to implement Google authentication services for user authentication. I've already integrated Laravel sanctum to allow users to log in and register successfully. This time, I want to add Google Identity services as an additional authentication ...

AngularJS custom directive for a select input module

I'm currently in the process of developing an AngularJS directive for a component that will be utilized multiple times across various sections of my System. At this point, I'm encountering a roadblock. Here's a basic example to illustrate w ...

Ways to provide information to an rxjs observer

It appears that most people find observers to be a piece of cake, but I personally struggle with them. I am trying to set up an observable that can receive a number input after it has been created, triggered by pressing a button. However, all the examples ...

Local comparison causing unit test failure

Uncertain as to why this is not working properly with Dojo doh.t(formatedValue.localeCompare("16,91 $CA") === 0, "incorrect french formatting") The value of formattedValue is definitely "16,91 $CA" so I am certain it should be a match. However, when I at ...

Struggling to locate div#ID from the loaded fixtures with the Jasmine JS Framework

I successfully loaded my fixtures by using the following code: var fixture = loadFixtures("path/fixture.html"); Now, I am attempting to identify a specific DIV element with the ID #ID using the script below: expect(fixture.find('DIV#ID')).toBe ...