How to decide if I should use the Post method

Coreysan 1,651 Reputation points
2023-04-11T23:42:14.1266667+00:00

I'm working on a web store, and I'm at the part about adding a product when the user clicks "Add to Cart". I can do either:

  1. Write a form in the view with method=post
  2. Leave the form out, and use <a type="button" asp-action="Details" asp-route-id="@Model.Id">

Does it matter which technique I use for this event? I use POST in other places for sure, but when I'm just passing an integer, and adding product to a session variable, do I need to use a form?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xinran Shen - MSFT 2,091 Reputation points
    2023-04-12T02:25:19.23+00:00

    Hi @Coreysan , From your question, Both of these two methods can pass data to backend. But if you only want to pass an integer, I prefer to using the second method. Many platforms like Microsoft Q&A, Stack overflow are using <a> tag to pass id to backend. User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Xinran Shen


0 additional answers

Sort by: Most helpful