How to pass value from View to Controller

Jagjit Saini 106 Reputation points
2021-06-07T03:45:39.167+00:00

Hi

I want if user clicked on Update button then Update value should be passed to Controller.
If Delete clicked then Delete value should be passed to Controller

Thanks

Developer technologies | ASP.NET | Other
{count} votes

1 answer

Sort by: Most helpful
  1. Chao Deng-MSFT 801 Reputation points
    2021-06-08T08:43:26.71+00:00

    Hi @Jagjit Saini ,
    I wrote a simple example, you can refer to it.
    Controller:

     public ActionResult Test()  
            {  
                  
                return View();  
            }  
            [HttpPost]  
            public ActionResult Test(string comment)  
            {  
                  
                return Json(comment,JsonRequestBehavior.AllowGet);  
            }  
    

    View:

    n9yNP.png
    Result:;
    m7pQD.png
    H8Mbx.png


    If the answer is helpful, please click "Accept Answer" and upvote it.

    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,

    ChaoDeng

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.