Let's say I have an OrderController which handles orders. The user adds products to it through the view, and then the final price gets calculated through an AJAX call to a controller action.

The price calculation logic is implemented in a seperate class and used in a controller action. What happens is that I have many views from different controllers that need to use that particular action. I'd like to have some kind of a PriceController that I could call an action on. But then the view would have to know about that PriceController and call an action on it.

Is it bad practice for a view to call an action on a different controller from which it was rendered?


This seems like a pretty reasonable solution to me.

A view that has to request information should, and can, be able to request that information from any appropriate controller - I don't think there needs to be a 1:1 mapping if that's what your implying there should be?

| improve this answer | |
  • Yes that's what I am implying. – marco-fiset Oct 24 '13 at 14:51
  • 1
    @marco-fiset: How would I get customer details from an order view? Would I have to add GetCustomer actions on all controllers that could potentially need to provide a link to the customer details? Yikes... very wet violation of DRY. Customer details should be taken care of in a single place. Hmm. Sounds like a customer controller with a customer view. And calling it from wherever one would like to be able to get the details of the customer. – Marjan Venema Oct 24 '13 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.