Saturday, October 29, 2016

HTTP GET or Post in MVC

In asp.net Web Forms, IsPostBack page  property is used to check if the request is POST or GET.
If IsPostBack Property returns true, then we knows the request is http post. Else the request is GET


In asp.net mvc use Request object Http Method property to check if the request is get or a Post Request






Example

First Let me add a controller.



Give any Name of the controller , I have given it as Home Controller.



Write the below code in the Home Controller as shown below

As we cannot have same Index method name twice so I have used Index_Post and specifying the Action Attribute Index.

Created a new method to check Wheather IsPost() is True or False.




Right click on the controller and Add View--Index.cshtml


and click on Add Button

After hitting the url you can see that IsPostback is false




In Debugging Mode after hitting Enter.You can see that Get  method is been called.





When  you click on Submit button you can see that it is calling the post method.

and the output is




No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...