tags:

views:

34

answers:

1

Hello,

Imagine I have a PartialView displaying a list of articles. And I have a Repository/DAL function get me the newest (or whatever) 100 Articles. Now I want to display these articles using a grid in 5 columns. How can I display the first 5 in the first column, the next 5 in the next column an so on using that partial view. Ok I could put the list in ViewData and tell the PartialView something like skip(x).take(y). But what if the PartialView decides how much to display? (e.g. depeding on lenght of text)

Is TempData the right place where I could place a Index or something like that?

thanks, Lothar

A: 

No, TempData is for sending information to the next requests, in this case, there's only one request.

If the boxes are more or less the same size, I'd output them as divs and use css float:left; to position them next to each other. That way when a box doesn't fit, it'll fall down to the next line.

If you want to send additional data to your PartialView, you should create a ViewModel class containing two properties; one for the index and one for the article. To output the article grid you probably want to create a html helper method to move logic from the view.

svinto
Hi svinto,thanks for your answer. Probably my thinking was just wrong.I believe I have to populate the articles in the controller for each column (like viewdata["col1"], viewdata["col2"] and so on, or?But It's interessting that I can have Properties in the Model which can be changed in a partialview. I tried that one and it worked.
lothar42