Solved

Do MVC2 Views have Postback?

Posted on 2010-09-23
9
940 Views
Last Modified: 2012-05-10
My ASP.NET was never that strong, which is why I like the idea of my latest job to create a web app. using MVC2.  But I need to learn more before I am c onfident as I'd like to be with it.

Does the HTML get a postback?  I read that there is none.

Please explain this and also, why the Nerd Dinner MVC2 demo uses terms like GET and POST, and what they may mean otherwise.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 5
  • 4
9 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 33748114
It does post back..... sort of......but not in the traditional sense. The initial request to a page is usually a GET (i.e. request for information) which, if there are no parameters, results in a Create() action in the controller. When you submit data this results in a POST request to the server, which, for a new record, will result in a second Create call, only this time to an overload that accepts an instance of your model.
0
 

Author Comment

by:newbieweb
ID: 33748248
That helps.

What does this do?:
Html.BeginForm()

and is it related to a POST?
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 33748310
Html.BeginForm() is a Html helper method. It basically marks the start of the Form element in the page. It also helps to hook up the View to the correct Action and Controller, there are several overloads available if you want your form to target a different Controller or Action than it's default.
0
 

Author Comment

by:newbieweb
ID: 33748377
And please explain what this attribute does:

[HttpPost]
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 33748395
It marks an action on your controller as being responsible for handling POST requests.
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 33748418
So, for example, if you had a controller that handles creating new Customer you might have a controller like:
public CustomerController : Controller

{

    public ActionResult Create()

    {

        // handles the intial GET request that presents a View to allow data entry

    }



    [HttpPost]

    public ActionResult Create(Customer customerToCreate)

    {

        // handles the POST request when a user populates the View and submits it

    }

}

Open in new window

0
 

Author Comment

by:newbieweb
ID: 33748505
I am still not getting it.  In your example, how would how differently would the Create() function act if [HttpPost] were not used?

Also, I have this text from Nerd Dinner that highlights my lack of understanding.  Where is the GET and POST being received to differentiate between them?  

When the [HttpPost] attribute is applied to overloaded action methods, ASP.NET MVC automatically
handles dispatching requests to the appropriate action method depending on the incoming
HTTP verb. HTTP-POST requests to /Dinners/Edit/[id] URLs will go to the above Edit
method, while all other HTTP verb requests to /Dinners/Edit/[id] URLs will go to the fi rst Edit
method we implemented (which did not have an [HttpPost] attribute).
0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 total points
ID: 33748570
I'll try and break this down into steps.

When you open a brand new browser window an point it at something like "http://NerDinner/Dinners/Edit/5" you are making a GET request to the Edit action of the Dinners controller for record id 5.
The view will then present you with a form to edit that dinner.
When you click Save (or whatever button is there) you are making a POST request (i.e. sending data back to the server) to the same URL.
In MVC terms this gets redirected to the Edit action of the Dinners controller and because it is a POST request the call gets directed to the version of Edit that has the HttpPost attribute applied to it.
0
 

Author Closing Comment

by:newbieweb
ID: 33748907
Thanks for all the help.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now