tags:

views:

34

answers:

1

Hi,

I want to create a form for creating an order. So I have an 'Order' controller. One of the first steps will be to select an existing person to send this order to.

I'm thinking the Create() action method on OrderController will put a new Order object in session.
Then I'll need a link that will redirect to another controller, then return a customerID int to this Create() method.

I will have either a SearchController with a FindCustomer() action method, or a Search() action method on the CustomerController.

I have tried the first way. But what I am doing looks pretty messy. Especially considering that I'll need to do this at least one more time on this form, redirecting to the ItemsController to return items to add to the order.

What's the best way to design communication like this between controllers?

thanks in advance, SO

A: 

I'm not sure why you think you need other controllers for this. In your GET Create action, put the available Customers and Items in to ViewData, and then in your view put some controls for the user to select values. Then they will be POSTed to your POST Create action, and you can bind & save it in your Order object. You could have a separate action for adding Items to the Order if that gets too complex. But it could still be on the same OrdersController.

HTH, or let me know if I'm not getting what you're trying to do.

dave thieben
Thanks for the help, I appreciate it. Thing is, there may be thousands of customers or items to add, and each of these has dedicated controllers for managing them, so I didn't think it's appropriate for OrderController to be accessing the other repositories to return results.
rob f.b.
well, the OrderController isn't doing the work of managing them, it's just going to query for a list of customers. it's up to you to create a UI that works to select customers from a large dataset. an example would be an autocomplete type text box, or a modal popup that lets the user search the customers. if you're using AJAX to do these things, then you can have your AJAX methods hit your CustomersController to fetch data.
dave thieben