HOW CAN WE RESTRICT MVC ACTIONS TO BE INVOKED ONLY BY GET OR POST?

Anupam Mishra

Total Post:135

Points:949
Posted by  Anupam Mishra
 1563  View(s)
Ratings:
Rate this:
Hi All,
How can we restrict MVC actions to be invoked only by GET or POST? Please give me a solution.

thanx.
  1. Anupam Mishra

    Post:135

    Points:949
    Re: How can we restrict MVC actions to be invoked only by GET or POST?

    I have got it, its answer. Details explanation is below:
    We can restrict the MVC action with the HttpGet or HttpPost attribute to restrict the type of HTTP calls. For example,In below code DisplayStudent action can only be invoked by HttpGet. If we try to make HTTP POST on DisplayStudent, it will throw an error.


    [HttpGet]
    public ViewResult DisplayStudent(int id)
    {
        Student objStudent = Studentss[id];
        return View("DisplayStudent",objStudent);

      Modified On Feb-14-2016 11:02:28 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!