tags:

views:

38

answers:

2

I'm building an ecommerce application and I have a controller that is responsible for the buy process.

What I've noticed in creating the methods within these controllers is that each method is responsible for processing input from previous view.

So I have a Quote method that returns a Quote view, and the user is interacting with the view and its form is posting to a Payment method. That means the Payment method is actually processing information from the quote page before returning the payment view. The "Payment" view is posting to a "Completed" method (which is procesing the payment information before returning a page that shows the purchase is completed).

Coming from a webforms background it seems weird that each method is actually processing information from the previous page. So the Payment method is not "controlling" Payment, its actually "controlling" the Quote page information before returning a payment view.

Am I looking at this in the wrong way?

+1  A: 

Its not that a Controller method is processing the previous view but instead, you are telling your view to pass the information to that controller. Its not necessary to pass the View's information to another Controller method. It depends on how you code your controller-view relationship.

For example you have a Quote View and a Quote method in your controller. You can have 2 methods for Quote in your controller, one is responsible for displaying the information and the other to process the information passed from the view.

public ActionResult Quote()
{
    return View();
}

[httpPost]
public ActionResult Quote(FormCollection quoteForm)
{
    // process your Quote form
    return RedirectToAction("Payment");
}

For my Quote View

<% using(Html.BeginForm()) { %>

    // my html form here

    <input type="submit" text="submit" />
<% } %>

I will code my controller this way so that I will not be confused of what controller method is processing my View. Where when I submit the form in my Quote it will submit the information to the Quote method that accepts httpPost. Although what Tassadaque said here is advisable for your kind of situation.

rob waminal
+1 The OP should be looking at the Post/Redirect/Get pattern.
Matthew Abbott
Thanks Matthew..
rob waminal
Yes, the PRG pattern looks like it will allow me to better manage the workflow whilst avoiding problems of duplicate submission. Thanks Mathew.
StephenLewes
Found this link: http://www.eworldui.net/blog/post/2008/05/ASPNET-MVC---Using-Post2c-Redirect2c-Get-Pattern.aspx
StephenLewes
Say for example that my ActionResult "Quote" was accepting form values from a form that could be hosted on any site. Then it would have to process the input from that form before returning a View. However, within that View there is a form that posts any choices the user makes on that page. Therefor my ActionResult "Quote" would have to deal with 2 different post scenarios. One that accepts form values to render the first showing of the View page, and also one that takes values from the View page to process before redirecting to the next step. How do I deal with that?
StephenLewes
I guess the simple answer is to create an ActionMethod that processes the information from the external quote form before passing by redirect to the ActionMethod that renders the Quote view.
StephenLewes