The HTTP post method is mistakenly perceived as the HTTP get method

I was working on a JavaScript snippet that looks like this:

$.ajax({
                type: "Post",
                contentType: 'application/json',
                url: "../api/Pointage/GetPointages",
                 data: JSON.stringify({
                    laDate: DateConsultation,
                    lstcols: Collaborators,
                    lEquipe: equipe,
                    Type: 3,
                }),
                success: function (data) {
                    console.log(data);
                    call3(data);
                }
            });

The service method's signature is as follows:

[HttpPost]
public List<ItemStatistiquesPointageMonth> GetPointages(Nullable<System.DateTime> laDate = null, List<Collaborateur> lstcols =null, Nullable<int> lEquipe = null, int Type = -1)

Despite this setup, I am facing an issue where the service appears to be unreachable!

Can you help me understand why this problem is occurring and what steps I can take to resolve it?

Answer №1

Develop a model class that mirrors the object you are creating in the client-side application

public class DataModel
{
    public Nullable<System.DateTime> lastDate { get; set; }
    public List<Collaborator> collaboratorsList { get; set; }
    public Nullable<int> teamId { get; set; } 
    public int Category { get; set; } 
}

Next, include it in the method with the FromBody attribute

[HttpPost]
public List<ItemStatisticsMonthlyReport> RetrieveStatistics([FromBody] DataModel data){}

Answer №2

Build a Model using the specified parameters and send it to your post method

[HttpPost]
public List<ItemStatistiquesPointageMonth> GetPointages([FromBody] MyModel model)

Remember to include dataType: "json"

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

Unable to deploy .Net Blazor Application: The app has been abruptly ended due to a signal: SIGHUP

I encountered an unexpected issue while trying to publish my Blazor application. The following error occurred: dotnet publish /usr/local/share/dotnet/dotnet publish "/Users/alvinstefanus/Documents/Projects/MyApp/MyApp/MyApp/Server/MyApp.Server.csproj& ...

What are the differences between Node's bcrypt and bcryptjs libraries?

When it comes to using bcrypt in Node, the abundance of libraries available can be overwhelming. Among the top packages on npm are bcrypt with 247k downloads per month bcryptjs with 337k downloads per month (any other options worth considering?) What s ...

VueJS throws an error indicating that the object cannot be extended

I have encountered an issue while trying to update the promo object by adding a new field called colspan. Unfortunately, I am getting this error: uncaught (in promise) TypeError: Cannot add property colspan, object is not extensible at eval (eval at ...

How can you display a doughnut chart with a custom color to represent empty or no data, including doughnut rings?

I have integrated a doughnut chart from chartjs into my Vue project using vue-chartjs. Currently, the doughnut chart does not display anything when there is no data or all values are empty. Is there a way to customize the color and show the entire doughnu ...

Increase the worth of current value

Whenever a user enters their name into an input box, I want it to be shown after the word 'hello'. However, currently, the word 'hello' gets replaced by the user's name instead of being displayed after it. var name = document.ge ...

How to Play a Sound file without needing winmm.dll or microsoft.visualbasic.dll_IMPORTED

Currently, I am developing a program using Delphi prism with the aim of running it on both Windows and Linux (mono) from a single project. However, I face the challenge of playing sound files on these platforms without relying on winmm.dll or microsoft.vis ...

Using ReactJS to search for and replace strings within an array

A feature of my tool enables users to input a string into a textfield and then checks if any words in the input match with a predetermined array. If the user's string contains a specific name from the array, I aim to replace it with a hyperlink. I&a ...

Is it possible to change all text to lowercase except for URLs using .tolowercase()?

Currently, I am facing a challenge with my Greasemonkey script. The use of .tolowercase() is causing all uppercase letters to be converted to lowercase, which is disrupting URLs. I have explored alternatives like .startswith() and .endswith(), considering ...

How do Polymer elements and AngularJS directives differ from each other?

Exploring the Polymer Getting Started guide reveals a practical example showcasing Polymer's capabilities: <html> <head> <!-- 1. Shim missing platform features --> <script src="polymer-all/platform/platform.js"></ ...

Setting the default font size in CKEditor is a helpful feature that allows you to

I'm struggling to set a default font size for a specific CKEditor Instance. Despite my efforts in researching online, I haven't found a solution that addresses my issue. On a webpage where users can input website content, there are three Editor ...

What steps should I follow to create an automatic image slider using Fancybox that transitions to the next slide seamlessly?

*I've recently ventured into web design and am currently experimenting with Fancybox. I'm interested in creating a slider with 3 images that automatically transitions to the next image, similar to what is seen on this website: Is it feasible to ...

What is the best way to transform this code into a JavaScript string that can be evaluated at a later time?

I need a way to save this snippet of JavaScript code, make some modifications to it, and then evaluate it at a later time. Unfortunately, the online converter I tried using didn't produce the desired outcome. Original Code $Lightning.use("c: ...

Leverage the Ajax response within a Jade template

I'm currently utilizing ExpressJS with the Jade template engine. My goal is to achieve the following: Within a Jade file, I need to extract a variable that will be used in a JavaScript file. This JavaScript file will then make an Ajax request to the ...

`Thoughts on Difficulty Attaching Child Elements in JavaScript with appendChild`

I am having trouble with appending some HTML that is being received as a string in a div. For some reason, the appendChild method is not working as expected. Here is my JavaScript code: var doc = document.getElementById("products"); var notes = doc.getEle ...

What is the most efficient way to use map-reduce in TypeScript to filter a list based on the maximum value of an attribute?

Recently, I came across a list that looked something like this: let scores = [{name: "A", skills: 50, result: 80}, {name: "B", skills: 40, result: 90}, {name: "C", skills: 60, result: 60}, {name: "D", skills: 60, ...

Move the cursor and watch as the Hover Image seamlessly follows its path

Currently, I am attempting to create an interactive hover effect with an image that moves along with the mouse cursor. While I have come across various resources for achieving this effect, the limitation of working within a Wordpress theme restricts my ab ...

What is the correct way to use variables to reference whether an item is odd or even in an ng-repeat loop?

Is there a way to access the variables $odd and $even within ng-repeat using a variable for reference? Here is what I have attempted: <ng-repeat="item in items" ng-if="$odd">these are odd{{item}}</div> <ng-repeat="item in items" ng-if="$eve ...

Does Vuejs emit an event when a specific tab becomes active in boostrap-vue?

I am looking for a way to display and hide a section on my page when a specific tab is active, and close it when the tab is inactive. I have tried using the forceOpenSettings and forceCloseSettings methods for opening and closing the div. Is there an event ...

Ensure that all of the text boxes are aligned perfectly in the same vertical position

Is there a way to align all the textboxes in the same vertical position without using tables, only using HTML and CSS? The textboxes should start just after the label and follow the width of the label. Also, all labels are left-justified. Code :: <d ...

Ways to verify if all files have been loaded using Firebase.util pagination

Is there a way to confirm if it is necessary to stop invoking the loadMore() function, since all documents have been retrieved from the database? In the code snippet provided, Ionic framework is used as an example, but the same concept applies to ng-infin ...