The AngularJS $http.post method is returning null when communicating with the ASP.NET MVC controller

In my AngularJS service, I am encountering an issue with the following code snippet:

$http.post("/EditWorkout/GetId", data).error(function (responseData) {
            console.log("Error !" + responseData);
        });

Furthermore, in my ASP.NET controller, I have the following method defined:

[System.Web.Http.HttpPost]
public JsonResult GetId(string routineId)
{
    try
    {
        string x = routineId;
        return Json(new {success = true});
    }
    catch (Exception ex)
    {

        return Json(new { success = false, errorMessage = ex.Message });
    }

}

While debugging, I noticed that when reaching

return Json(new {success = true});
, the breakpoint is hit. However, the value of routineId is unexpectedly null, even though the data sent using Angular's $http.post contains a value.

What could be causing this issue?

Answer №1

give this a shot:

$http.post("/UpdateExercise/RetrieveID", { exerciseId : value}).error(function (resultData) {
            console.log("Oops, there was an error: " + resultData);
        });

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

Creating objects based on interfaces

After looking at this straightforward code: interface int1 { aa: string, bb: number, } const obj1:int1 = {} //#1 function fun(param_obj:int1) { //#2 } I am curious as to why the compiler throws an error: Type '{}' is missing the fol ...

What is the best way to link a CSS file within a PHP document's head section and a JavaScript file just before the closing body tag?

How can I properly include a CSS file in the head section of a PHP file? Currently, I am including CSS like this: <?php include('./includes.header.html'); ?> <style><?php include('./test.css'); ?> </style> The ...

When extracting text using .text(), remember to include spaces between td elements

Is there a method to include space between td's when using .text()? I have searched extensively on Google but could only find information on how to trim space. The code I am currently using is as follows: for (var i = 0, len = rows.length; i < l ...

Node (Sync/Synchronize) is unable to locate the binaries for fibers

Despite countless attempts at finding a solution, I still can't seem to resolve this persistent issue...I'm familiar with this question, but unfortunately, it didn't work for me :( The dilemma at hand: It keeps showing the error message: n ...

Having troubles with delayed state changes due to setState being used within useEffect

I have been working on a slider effect using React Hooks and Redux, and here is the code I am using: const Barchart = ({chartData}) => { let newArray = [] let len = chartData.length const [XArray,setXArray]=useState([chartData]) const [ ...

Switching image display through data toggle

<a href="#demo1" data-toggle="collapse"><h3 style="color:#0F77CD;">Form</h3></a> <div id="demo1" class="collapse"> <asp:CheckBox ID="CheckBox1" runat="server" Text="Capsules" /><br /><br /> <asp:Check ...

Switching on click using jQuery

I'm having some difficulties with my code and I can't quite figure out how to solve the problem at hand. To be honest, I'm not even sure what the exact question is here. If it seems a bit confusing, I apologize - I'm still new to Jquery ...

Refreshing the display in an AngularJS directive

I've developed a custom directive for handling file uploads in my AngularJS application. The directive is used in multiple places, including on the same page more than once. Each instance of the directive is supposed to display the uploaded file name ...

Neglected to update the class for an element using jQuery

When the input field is blurred and empty, I want to add the class ".has-error". After entering text into the input field, the class ".has-error" should be removed and the class ".has-success" added. The ".has-error" class is being removed but a new clas ...

Enhance the appearance of a row on the table with a lumin

Is there a way to create a glowing effect around a single row in a table, similar to the style shown in this example? Here's the code that can help achieve this effect, sourced from CSS/HTML: Create a glowing border around an Input Field .glowing-bo ...

Steps to activate JavaScript upon selecting a dropdown menu item

My webpage has two dropdown boxes for car makes and models. I want all the models of a selected make to display in the next box. Currently, the models only show up when the dropdown is clicked using the code below. window.onmousedown = function(e){ th ...

Using Vue.js and axios to manipulate injected HTML content

I am currently working on a project using vue.js and axios to fetch the latest post content from a specific category of a WordPress site using REST API. The post content is always in the form of an ordered list (OL) which will then be displayed as a carous ...

I am facing an issue with localStorage.clear() not functioning properly in Internet Explorer when using Protractor

Having trouble clearing localStorage at the beginning of each test, specifically in Internet Explorer 11. This issue does not occur in Chrome or Firefox. Below are the codes we have tested: browser.executeScript('window.localStorage.clear();'); ...

Transferring a variable from PHP to JavaScript

Can you help me figure out why my PHP to JavaScript variable transfer script is not working as expected? Any advice would be appreciated. Thank you. <!DOCTYPE html> <HTML> <HEAD> <META charset="UTF-8"> <TITLE>Trans ...

Transform AngularJS into Angular through modifying the names of the directives and adjusting the framework to accommodate these new directives

I have a section of HTML code that includes AngularJS directives, and I am looking to convert it to Angular 8. Within my Angular project, I have created a custom component named destination. In the TypeScript file for this component, called destination.com ...

considering multiple website addresses as one collective entity for the Facebook like button

Currently, I am tackling an issue on a website that employs a custom CMS which automatically generates URLs based on the titles of articles. The main problem faced by our contributors is that when they update the title of an article, it creates a new URL ...

I am currently encountering an issue with a code snippet that is not performing as anticipated and require clarification

import React, {useEffect, useState} from 'react'; export function App(props) { let [state, setState] = useState(2); console.log('outside', state); useEffect(()=>{ document.querySelector('.btn').addEventListener( ...

Is it possible to dynamically assign class properties from an array in JavaScript/TypeScript?

Greetings for the assistance in advance. Currently, I am working with TypeScript, but I believe any JS solution will suffice. I aim to create something akin to the following: class ExcelData { 'Id 1': items[0].id, 'Quantity 1': item ...

Issue: Error message - Unhandled promise rejection: NodeInjector error - ControlContainer not found

I'm having trouble validating a form and encountering an error. I tried implementing the suggestions provided in the following threads without success: Getting error suddenly in Angular Error: NodeInjector: NOT_FOUND [ControlContainer] Using forms i ...

Use `$$state: {…}` within the request rather than the data

When attempting to send a request with data, I am only getting "f {$$state: {…}}" in the console. $scope.createTask = function () { var req = $http.post('api/insert', { title: $scope.newTitle, description: ...