Troubleshooting issue with Angular 11 and .Net post method malfunctioning

When attempting to send data from Angular to .Net, I am encountering an issue where the breakpoint in the Controller C# is not being hit. Do I need to make any additional configurations? Previously, I have successfully sent data in this manner in Angular 8 and it was functional.

C#

public class UpdateViewModel
{
    public int Id { get; set; }
    public string Title { get; set; }
}

[HttpPost]
[Route("delete")]
public void Delete(UpdateViewModel model)
{
    //return Ok();
}

TypeScript

var model = {
    Id: 1,
    Title: 'test'
}

return this.http.post(this.baseURL + "home/delete/", model)
.pipe(
    retry(1),
    catchError(this.errorHandler)
);

Answer №1

The angular http client utilizes observables for handling requests. This means that the request will only be made when you subscribe to the observable using either .subscribe() or .toPromise().

Here is an example of how you can implement this in your code:

  return this.http.post(this.baseURL + "home/delete/", model)
    .pipe(
      retry(1),
    )
    .subscribe({
      error: this.errorHandler
    });

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

Leveraging Entity Framework across Multiple Databases and Providers within a Single Project (Combining SQL Server and MySql)

Background: I've successfully developed an application that can interact with multiple SQL Server databases using Entity Framework code first without any issues. Switching between contexts has been seamless until I attempted to integrate a new MySql ...

Unable to remove a node from the Firebase Database

In my attempt to delete, I use the function in the following way: <div *ngFor="let out of cart_checkouts"> <button type="button" (click)="RemoveCheckoutRecord(out.checkoutID)">Delete</button> </div> Th ...

Whenever the return condition is false, make sure to subscribe to the Angular CanActivate Guard

In my UserAccessGuard class, I have a method that captures the current path and compares it to the user's available paths. However, I am facing asynchronous problems because the condition inside the subscribe block causes my Hasaccess variable to rema ...

Tips for deserializing JSON with random string keys in Unity's C# using JsonUtility?

When working with Unity and C#, utilizing JsonUtility is key. Let's say we have a JSON string like this: { "1,1":"dd", "2,1":"abc", "2,2":"123" } The number and content of keys can vary. How can we deserialize this JSON and map it to our ...

To avoid TS2556 error in TypeScript, make sure that a spread argument is either in a tuple type or is passed to a rest parameter, especially when using

So I'm working with this function: export default function getObjectFromTwoArrays(keyArr: Array<any>, valueArr: Array<any>) { // Beginning point: // [key1,key2,key3], // [value1,value2,value3] // // End point: { // key1: val ...

Different Styles of Typescript Function Declarations

I recently started experimenting with Typescript and I'm a bit confused about the differences between these two method declarations: onSave() { /*method body*/ } public onSave = () => { /*method body*/ } Additionally, could someone point me in th ...

Issue with Angular 4 Bootstrap Carousel

I encountered a console error that I couldn't resolve while working on my project. The technology stack involves Angular 4 and Bootstrap. Unfortunately, my frontend developer is unavailable this weekend, and I'm unsure if there are any missing d ...

What is the best approach to implementing a blur function for a specific input within a parent component?

I have created a custom input field as a separate component. I want to include multiple input fields in the parent component using directives: <app-input ...></app-input> My goal is to pass the blur event/function to the parent component speci ...

The React app encountered a post request that was sent with a null object

I've been working on a React application that allows users to create contacts and schedule meetings with them. My backend setup involves using Express for the server and routing, along with postgresql for storing contact information in a database. T ...

Exploring how process.argv in NodeJS can be utilized within JavaScript code compiled by

I'm having trouble compiling a basic TypeScript file using webpack (with 'awesome-typescript-loader') that needs to access command line arguments. It seems like the compiled JavaScript is causing a problem by overriding the Node 'proce ...

You cannot call this expression. The data type 'Boolean' does not have any callable signatures

As I delve into learning a new set of technologies, encountering new errors is inevitable. However, there is one particular type of error that keeps cropping up, making me question if I am approaching things correctly. For instance, I consistently face t ...

Choosing a component without an identifier

Trying to select an element from a webpage can be a bit tricky. After inserting a control into the page and needing to set some values for an element inside the control at pageload from C# code, you may encounter issues with id prefixes being appended due ...

Encountering difficulties during the installation of Angular 6.0.8

We encountered an error during the Angular installation process which resulted in Angular not being installed correctly. D:\software\node-v8.11.2-win-x64>npm install -g @angular/cli D:\software\node-v8.11.2-win-x64\ng -> ...

Angular: Unable to load todo list when filtering results

I am currently developing a simple todo application using Angular. I have encountered an issue where filtering results from an array imported from services does not happen in real-time. The filtering only works when I navigate to another page (since it&apo ...

Error received: MVC, Browser indicates that the website has redirected too many times while attempting to access a file stored within a restricted folder governed by the web.config file

My goal is to limit access to the Music folder on my website for anonymous users. To achieve this, I added the following code to the web.config file within the Music folder: <?xml version="1.0"?> <configuration> <system.web> ...

Obtain non-numeric parameters from the URL in Angular 2 by subscribing to

How do I handle subscribing to a non-numeric parameter from a URL? Can the local variable inside my lambda function params => {} only be a number? Here's my code: getRecordDetail() { this.sub = this.activatedRoute.params.subscribe( ...

Using Typescript to implement an onclick function in a React JS component

In my React JS application, I am using the following code: <button onClick={tes} type="button">click</button> This is the tes function that I'm utilizing: const tes = (id: string) => { console.log(id) } When hovering ov ...

The MouseClick event fails to trigger upon clicking

Encountering an issue with assigning a function to the MouseClick event outside of my form class. The event does not trigger when I click the mouse button. class Animator { Form1 _form = new Form1(); Timer GameTimer; PictureBox GameWindow; ...

typescript error: referencing a variable before assigning a value to it in function [2454]

I am currently in the process of creating a store using nextJS I have two variables that are being assigned values from my database through a function let size: Size let ribbonTable: Ribbon async function findSizeCategory(): Promise<v ...

The problem encountered with Angular ngrx: TypeError when attempting to freeze array buffer views containing elements

I'm running into a problem with ngrx. I have an array in my state to which I am trying to add objects. Everything seems to be working fine as I can see the values in my store when I console log them. However, the redux dev tools and console are throwi ...