The view should never call the BLL or the Controller. Ever. I fell
into this trap when building my Components. It made my Controllers
untestable.
bcsmith100:should the view invoke the controller for calls or should I just place the Get<Details> calls in the code behind of the view?
Neither! No way. Absolutely not.
Lazy loading is different (slightly). The controller is giving the View an
object which will *Automatically* fill in the blanks, only if the View
asks for something that's blank. The View shouldn't call anything other than ViewData.PropertyTheHasntLoadedYet. It's your object which has the logic for loading the data.
public IList<Cake> Cakes {
get{
if( this._cakes == null )
this._cakes = BLL.GetCakesTheHardWay();
if( this._cakes == null )
this._cakes = new List();
return this._cakes;
}
}
So, initially Cakes hasn't been loaded because it takes too long and we only want to load them if needed. So, if someone requests Cakes from our object, but they haven't been loaded yet, we do the hard work to retrieve them. And if someone requests it again, we just returns the saved list. This way we don't have any calls to the BLL in the View.
However, I prefer to explicitly
specify which parts of the object to load, so that I get back a static
object that doesn't "do" anything.
Some people might say that lazy loading is still "Calling the BLL from the View" and technically I agree, even tho it is indirectly. But I think that's ok, because it's out of the View's control. However, I don't think a View should directly or indirectly call into a Controller, EVER. But that's just my honest opinion.