Unable to retrieve parameter while making a POST request

Need some help with attribute routing. I'm having trouble getting parameters from the HTTP body. The ConnectionID Class includes a property named CValue.

$('#btn').click(function () {
    $.ajax({
        type: "POST",
        url: "http://localhost:49289/api/Resolver/StartRun",
        data: { "CValue": connectionID },
        success: success,
        dataType: "json"
    });
});



[Route("api/Resolver/StartRun")]
[HttpPost]
public async Task<string> GetStatus([FromBody]ConnectionID connectionID)
{
}

Answer №1

To avoid CORS, consider changing your path to a relative one:

url: "/api/Resolver/StartRun",

This should resolve any issues. Below are some simple examples demonstrating the solution.

JavaScript

<script>
        $.ajax({
            type: "POST",
            url: "/api/Resolver/StartRun",
            data: { "CValue": "123" },
            success: new function(){},
            dataType: "json
           });
</script>

Controller

    [Route("api/Resolver/StartRun")]
    [HttpPost]
    public async Task<string> GetStatus([FromBody]ConnectionID connectionID)
    {
        return "test";
    }

Class

public class ConnectionID
{
    public string CValue { get; set; }
}

Screen shot

I'm confident in the parameter being populated, even though I can't provide a screenshot at the moment. If you follow the above steps, everything should work as expected. :)

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

"Enhance your Magento store with the ability to showcase multiple configurable products on the category page, even when dropdown values are not

As I work on adding multiple configurable products to a category list page in Magento 1.7.2, I am facing some challenges due to using the Organic Internet SCP extension and EM Gala Colorswatches. While following tutorials from various sources like Inchoo a ...

What is the best way to update the state while invoking a component?

Just starting out with react and already hitting a roadblock. I've created an Article Topper component that features a logo, title, and share buttons, which is repeated throughout the site above each article. The issue I'm facing is updating the ...

Customizing pressed row styles and properties within a map iteration in React Native

How can I modify the style of a single item in a list when a button is pressed in React-Native? I want only the pressed item to change, not the entire row. Here is my attempt at implementing this: //hooks const [activeStyle, setActiveStyle] = useState( ...

What is the process for retrieving an Object from $cookies?

I've encountered an issue where I'm storing a user object on a Cookie and, upon the client's return visit to the site, I want to utilize this object's properties. However, upon the client's return, my cookie object appears as [obj ...

What steps can be taken to remove a server-side validation error message once the user has inputted the correct value?

I'm facing an issue with server-side validation messages on my form, which includes fields for Name, Mobile, Email, and Message. While JQuery validation works fine, clearing the error message after user input is causing a problem. Using AJAX to submi ...

The issue of VueRouter malfunctioning in history mode within Wordpress

I have integrated Vue into my Wordpress theme, but I am facing an issue with the router when setting mode: 'history'. The site goes blank and even after trying to configure the .htaccess file, nothing seems to work. My project is located in the V ...

My Javascript code initiates an AJAX request before any other operations are executed

I am facing an issue with my Flask application and client-side JavaScript. I am trying to send an object using AJAX from my JavaScript to the Flask application running on the server side. However, the AJAX request is being sent before the rest of my JavaSc ...

Retrieve the div element by calling a scriptlet with JavaScript

I am facing an issue with a web page that includes a scriptlet like this: <div id="flash_chart"> <%=content_data['report_text']%> </div> The variable content_data['report_text'] contains a lengthy string ...

Manipulating arrays in JavaScript through HTML processing

I'm encountering an issue while trying to send an array to a JavaScript function. Here's what I have so far: Within the controller: @data = [{date: '2014-08-17'}, {date: '2014-08-20'}].to_json In the view: <%= content_t ...

Utilizing a particular iteration of npm shrinkwrap for project dependencies

When deploying my node.js app to Appfog, I encountered a problem with their install script failing to parse npm-shrinkwrap.json. The current format of a dependency in shrinkwrap.json is as follows: "async": { "version": "0.2.10", "from": " ...

Javascript Error - Issue with Fuse.js: e.split() function is not recognized

Scenario - I am in need of implementing a fuzzy search feature, and therefore utilizing fuse.js for this purpose. I obtained the code snippet from fuzzy.min.js at https://github.com/krisk/Fuse/blob/master/src/fuse.min.js Challenge - Despite using the cod ...

Navigating through choices in select element using webdriverio

Sample HTML: <select id="random_text"> <option value="option1">asadka_TEST</option> <option value="option2">Peter Parker</option> <option value="option3">Clark Kent</option> <option value="optio ...

Clear Dropdown Selections prior to Submitting

When trying to change the value of the first dropdown list and reset the second dropdown before submission, I encountered an issue where the second dropdown still retains its previous selection upon submission. There is no submit button as the form is subm ...

"Creating a cascading dropdown in ASP.NET MVC: Making one dropdownlist dependent

This part of the platform is dedicated to creating job listings. Users are required to select an Area and Subarea when creating a job offer. Upon selecting an Area, relevant Subareas should be displayed. To get a visual representation of the table structur ...

Utilizing keyboard shortcuts for webpage navigation (within a content script)

Just to clarify, I'm not looking for code assistance right now. I mostly need a starting point. My goal is to create a Chrome browser extension that enables me to use keyboard keys for navigation on a specific webpage. The page in question belongs t ...

Trouble displaying Django Ajax values in drop-down menu despite successful retrieval

I have implemented a search feature using Ajax to display blog titles in a drop-down suggestion list. Despite not encountering any errors and being able to view the data populated through inspect element > network > response in the browser, the temp ...

Turned off jquery on a specific div in order to resolve compatibility problems with Vue.js

Currently, I am working on a Drupal project which includes JQuery in all pages. We have recently introduced Vue.js for creating dynamic components directly in the HTML pages (not for building a single-page application). However, we are facing an issue whe ...

Modify certain user configurations without altering all settings in one specific form using PHP and MySQL

I am in the process of developing a PHP website with data stored in a MySQL database. Currently, I have completed the sign-up, login, and logout functionalities. However, I am looking to enhance user experience by adding a section where users can adjust th ...

Whenever a query is entered, each letter creates a new individual page. What measures can be taken to avoid this?

Currently, I am working on a project that involves creating a search engine. However, I have encountered an issue where each time a user types a query, a new page is generated for every alphabet entered. For instance, typing 'fos' generates 3 pag ...

Is there a way to ensure that the line numbers displayed for JavaScript errors in Chrome are accurate?

I suspect either my webpack configuration or my npm run dev script are causing the issue, but I'm unsure of what exactly is going wrong. While running my application in development mode, I encounter error messages like: Uncaught TypeError: this.props ...