MVC Programming Practices – Calling Controller Actions from Views

mvcprogramming practices

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?

Best Answer

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?