Loading
logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Softhacker
#1 Posted : Monday, May 13, 2013 12:57:04 AM(UTC)
Softhacker

Rank: Administration

Groups: Administrators
Joined: 3/10/2013(UTC)
Posts: 4

Hi All,

I am very new in MVC. I just started working on MVC3. Please help me to identify Get and Post request in MVC. I have to render few control in the view if it is Post request.

Thanks in advance
Sponsor
Softhacker
#2 Posted : Monday, May 13, 2013 1:01:06 AM(UTC)
Softhacker

Rank: Administration

Groups: Administrators
Joined: 3/10/2013(UTC)
Posts: 4

Hi,

I found the answer. There is a boolean property in MVC to identify whether request is Get or Post in the View like ASP.Net. Please refer below code:
ASP.NET MVC way:
Code:

      if (IsPostBack)
      {
          //Code
      }
      else
      {
          //Code
      }


MVC Razor way of doing the same:
Code:
@{ 
    if(IsPost)
    {
        //Code
    }
    else
    {
       //Code
    }
}

Edited by user Monday, May 13, 2013 1:04:17 AM(UTC)  | Reason: Not specified

saupadhy
#3 Posted : Sunday, December 22, 2013 7:13:20 PM(UTC)
saupadhy

Rank: Newbie

Groups: Editors, Registered, Administrators, Moderator
Joined: 5/6/2013(UTC)
Posts: 3
India
Location: Hyderabad

Hi Thanks for asking the question.

Best and simplest way I can think of is to create method in your controller and add the attribure [PostRequest].
By adding this aatribute, you ensure that this method is invoked only for Post request.
Add all you logic you want to this method.

PS: This will help in decision making in Controller and not the View. You method is bang on for review.

Hope this help :)

Edited by user Sunday, December 22, 2013 7:17:40 PM(UTC)  | Reason: Not specified

Users browsing this topic
Guest
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF | YAF © 2003-2018, Yet Another Forum.NET
This page was generated in 0.086 seconds.