开发者

MVC workflow question

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 Paymen开发者_如何学JAVAt 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜