top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How can we detect that a MVC controller is called by POST or GET?

+3 votes
589 views
How can we detect that a MVC controller is called by POST or GET?
posted Sep 15, 2014 by Muskan

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
 
Best answer

When Page get loaded first time (or) Reload it will Hit GET Method. If user doing any action from Page (eg: click the submit button) it will hit the POST Method

Example:

[HttpGet]
Public ActionResult TestMethod()
{
  //This Method will Hit when Page Reload
  return view();
}

[HttpPost]
Public ActionResult TestMethod(ModelClass Model)
{
  //This Method will Hit when user click any submit button in TestMethod View
  //User did any action from Page it will Hit POST Method
  return view();
}
answer Feb 3, 2015 by Balamurugan Kn
...