The controller method does not receive any parameters

After sending a post ajax request to the server side, I encountered an issue where the received parameters turned out to be empty or null.

I've tried several solutions to fix this problem, but so far nothing has worked. It seems like the root cause lies within the server itself.

If anyone has any insights or suggestions on how to resolve this issue, I would greatly appreciate the help.

    fetch('Home/AddMovie', {
        method: 'POST',
        headers: {

            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            movie: data_object
        }),

    }).then(res => res.text())         
        .then(text => {

        })  

        .catch((error) => {

            console.error('Error:', error);
        });

[HttpPost]
    public void AddMovie(Movie movie)
    {
        var movies = new List<Movie>();
        var newJson = "";
        using (StreamReader r = new StreamReader(JsonFilePath))
        {
            string json = r.ReadToEnd();

            movies = JsonConvert.DeserializeObject<List<Movie>>(json);
            movies.Add(movie);
            newJson = JsonConvert.SerializeObject(movies, Formatting.Indented);

        }

        System.IO.File.WriteAllText(JsonFilePath, newJson);
    }

Answer №1

Everything will fall into place

private void InsertFilm([FromBody] Film film) { } 

Update:

Eliminate the use of JSON.stringify(). Simply assign the object directly.

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

What strategies can I use to optimize the code for the function provided?

This function allows for the dynamic display of select tags for location selection based on employee designation. The current code functions correctly, but I believe it can be optimized further. // Function to activate different location options based on e ...

Node.js tutorial: Packing 2D boxes efficiently

Working on a web application using node js and in need of a box packing algorithm to determine the optimal solution. While I could attempt to create an algorithm from scratch (view http://en.wikipedia.org/wiki/Packing_problems), I'm curious if a simil ...

cordova and nodejs causing a communication problem

As a UI front end Developer, my expertise lies in user interface design rather than server side and port connections. I have successfully created a node server.js file that looks like this: var app = express(); var http = require('http').Server( ...

Get a specific value from a map using a regular expression as the key

Trying to extract a value from a map using a regular expression as the key: const nameMapping = new Map([ ['Name1', 'This is some name'], ['Name1_2', 'This is another name'], [/^[A]{1}[0]{2}/, 'Name from r ...

Proceed with executing the function only if the current date is before the specified date

I've created a countdown timer that can count both up and down from a given date. However, I want the countdown to only run in reverse and stop once it reaches the current date or any future dates. Currently, the alert message shows when the date is r ...

Multiple instances of child being added and modified are being triggered repeatedly

I am currently developing an app using both Ionic and Firebase as the backend. I have implemented code to watch for two separate events using child added and child changed, but I am running into an issue where it is firing multiple times. When checking the ...

How can I prevent ng-blur from triggering when ng-readonly is set to true in AngularJS?

I am currently working with AngularJS and have run into an issue when combining ng-blur with ng-readonly. Even though ng-readonly is set to true, ng-blur still triggers (if the input field is clicked and then somewhere else is clicked). In this example, n ...

retrieving JSON data within the controller

When I use the command console.log($scope.data), I am able to view my JSON file. Additionally, by using <div ng-repeat="item in data">, I can see all the items in the view. However, when I try console.log($scope.data[0]) or console.log($scope.data[0] ...

Having trouble with CSRF when trying to implement AJAX post in Django?

I am currently facing an issue with the ajax vote implementation on my article model: @csrf_exempt @login_required def like(request): args = {} if request.method == 'POST': user = request.POST.get('user') lu= re ...

Modify the checkbox status on a webpage

Hey there! I'm feeling a bit lost when it comes to setting checkbox values on an HTML page. It's all a bit vague to me at the moment, and I'm hoping you can help shed some light on the matter. Here's what I'm trying to do: I want ...

Display routes in React using the react-router package

Can I use a console command at runtime to display all routes in my application? Despite utilizing react-router, not all routes seem to be functioning properly. In Rails, you can retrieve a list of routes during runtime. ...

Establishing express routing results in API call returning 404 error indicating resource not found

I need some clarification on how to configure my Express routing using app.use and router. My understanding is that I can create a router and then attach it to a route using app.use() to handle all routing related to that route. Can someone assist me in ...

Find out the device's brand, type, storage capacity, and color

Can we identify the Make, Model, Capacity, and Color of a mobile device using React JS? Many existing node modules only detect the make and model. Is it feasible to also detect Capacity and Color? For example, Apple iPhone 11 Pro 64GB in Black. ...

Generating a dynamic row within a table using pdfMake

My JavaScript Array of Objects has the following structure: arr=[[1,2,3],[1,2,4],[3,5,6],[2,4,5]] I'm looking to remove the outer array from this data. The expected output is shown below. With this output, I plan to generate a table in pdfMake. The ...

Convert JavaScript object into distinct identifier

I have a data object where I'm storing various page settings, structured like this: var filters={ "brands":["brand1","brand2","brand3"], "family":"reds", "palettes":["palette1","palette2","palette3"], "color":"a1b2" }; This object is ...

Retrieve a collection of Vue components

My single page website has a simple component structure: <template> <div id="app"> <header /> <section-about /> <section-warranty /> <section-advantages /> <section-service /> <section ...

Watching a video play within a slider and transitioning seamlessly to an image once the video ends

I am currently facing an issue with a video playing inside a HeroCarousel slider. Before the slider, there is an image and after the slider, there is another image. This is my code: <div data-time="8000" data-prev-src="/media/splash/slider-left.png" ...

Leverage access tokens in React.js frontend application

After successfully creating an authentication API using Nodejs, Expressjs, MongoDB, and JWT, I am now working on a small frontend application with React-js specifically for Sign-up and Sign-in functionalities. While I have managed to integrate the Sign-up ...

Organize divs based on their attributes

Using inspiration from this SO post, my goal is to group divs based on their "message-id" attribute. The idea is to wrap all divs with the same "message-id" in a div with the class name "group". <div class="message" message-id="1"> ...

Protractor - readline issue with input not being prompted

For some reason, my code is not properly utilizing readline to capture input from the console. Instead of waiting for input, it just runs through without allowing any interaction. Can anyone help me figure out what's going wrong here? I need it to wai ...