Can't get HTTP PUT-request to work in Asp.Net Core

can definition
can synonym
can verb
can band
cant
can't
can.'' acronym
soda can

I'm trying to update an entry in the "game" table. However, my put-request in ASP.net never seems to trigger, and I can't figure out why.

This is controller in ASP.net:

[Route("game/{update.GameID}")]
[HttpPut]
public IActionResult updateGame([FromBody]Game update)
{
    var result = context.Games.SingleOrDefault(g => g.GameID == update.GameID);
    if (result != null)
    {
        result = update;
        context.SaveChanges();
    }
    return Created("", result);
}

And this is the code I use in Angular:

url:string;
constructor(private _http: HttpClient) {
    this.url = "https://localhost:44359/api/v1/"
};

putGame(id:number, game:Game){
    return this._http.put(this.url + "game/" + id, game);
}

Edit 1: I do have a list of GET-requests, which all work just fine. It's only the PUT-request that fails.


If you are using PUT request you need to add a resource id either to update or create new - so just don't combine your id with your object

[HttpPut("game/{id}")]
public IActionResult UpdateGame(int id, [FromBody]Game update) {
    //...
}

If you are using Asp.net Core you can just re-write your URL on your HTTP verbs attribute like the code above - So pass your resource id in the URL and bind your object in the body - Your URL should read as https://localhost:44359/api/v1/game/2

Hope this helps you - Happy coding !!

Verb Can, that behave in a particular way, and which have very particular uses as well. Can definition, to be able to; have the ability, power, or skill to: She can solve the problem easily, I'm sure. See more.


The route template parameter {update.GameID} is not standard to what is suggested by documentation

Assuming the game id is an integer review the following

//PUT .../game/5
[Route("game/{id:int}")]
[HttpPut]
public IActionResult updateGame(int id, [FromBody]Game update) {
    //...
}

Reference Routing to controller actions in ASP.NET Core

I would also suggest you review the logic of the action as I do not believe it is doing what you think it does with updating the entity returned from the context.

Can, Can was the leading avant-garde rock group of the 70s. Can experimented with noise, synthesizers, non-traditional music, cut-and-paste techniques, and, most  Define can. can synonyms, can pronunciation, can translation, English dictionary definition of can. to be able to, have the power or skill to: I can take a bus to the


Can you modify your defining route just like

[Route("game")]
[HttpPut]
public IActionResult updateGame([FromBody]Game update)
{
   //your code
}

And call from angular like

putGame(game:Game){
    return this._http.put(this.url + "game", game);
}

you can receive gameid from game object so don't need from url

Use can in a sentence, Can may refer to: Contents. 1 Containers; 2 Music; 3 Other; 4 See also. Containers[edit]. Aluminum can · Drink can · Oil can · Steel and tin cans · Trash can  can definition: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more.


Can, VerbEdit. can (third-person singular simple present can, present participle -, simple past could, past participle (obsolete except in adjectival use) couth). 110 synonyms of can from the Merriam-Webster Thesaurus, plus 97 related words, definitions, and antonyms. Find another word for can. Can: to bring (as an action or operation) to an immediate end.


The Official CAN / Spoon Records Website, can meaning: 1. to be able to: 2. used to say that you can and will do something: 3. to be allowed to: . Learn more. Can (stylised as CAN) was a German experimental rock band formed in Cologne in 1968 by the core quartet of Holger Czukay (bass, tape editing), Irmin Schmidt (keyboards), Michael Karoli (guitar), and Jaki Liebezeit (drums).


Can, 1.4Used to indicate that something is typically the case. 'antique clocks can seem out of place in modern homes'. More example sentences. A Controller Area Network (CAN bus) is a robust vehicle bus standard designed to allow microcontrollers and devices to communicate with each other's applications without a host computer. It is a message-based protocol , designed originally for multiplex electrical wiring within automobiles to save on copper, but can also be used in many other