Problem with NVelocity, foreach and two lists

There is an easy way to solve the following problem.

Let's say I bring an IList with some books in my controller from my model. Now I want to enrich the output and get a preview from Amazon with another model from the external structure and get another IList.

Now I put both Eilists in a bag of properties.

In NVelocity, I use #foreach for BookList, but how can I access the amazonbook list with preview privileges? I cannot use $ amazonbook [index], where index will be isbn. Do I need to put both lists in one big list with a simple onject containing only two other objects?

Remember that both models are from different frameworks and cannot be placed in the same structure. Both structures must remain separated. I am trying to solve the problem of NVelocity and, of course, this problem is just an example, we do not sell books;)

+5
source share
2 answers

There may be a simpler solution, but I would create a third class such as

class BookList{
       MyBookObject     a;
       AmazonBookObject b;
}

a list of this third class can be immediately passed to your submission.

+1
source

Have a look here: http://www.castleproject.org/monorail/faq.html#NVelocity%20View%20Engine

You can access the dictionary in NVelocity through

$amazonbook.get_Item($index) 
+6
source

All Articles