简体   繁体   中英

How to save data into database using HttpGet in ASP.NET MVC?

I know its not a good practice to save data using HttpGet , rather than we should use HttpPost , but if I want to achieve the same using HttpGet with an action method of my ASP.NET MVC controller, how can I do that?

You really should try to keep the good practices, But assuming that you want to pass data in the body of the request: I believe you can do something like this:

 [HttpGet] [AllowAnonymous] public IActionResult RequestMethod([FromBody]RequestModel myModel) { if (myModel == null) { return BadRequest(); } // your logic here }

The FromBody annotation allows you to add a body to the HTTP GET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM