views:

100

answers:

2

Hi guys, I am building a site in ASP.NET MVC. I intend to replicate the way StackOverflow displays its posts. Are these guys using a repeater control in ASP.NET MVC? I do want complete control on the markup rendered, but I also want pagination.

What is the best approach in such a case.

+1  A: 

In MVC, I would suggest using a combination of a LINQ query in your controller (or in a repository, within a function called from the controller), a for loop in your view, and depending on on how complex the items you want to display are, a partial view inside the loop.

For pagination, you might pass start and count parameters to a function to get a section of a list of objects via LINQ. For example:

Function sliceList(ByVal startIndex As Integer, ByVal count As Integer) As Generic.List(Of myObject)
   Dim FullObjectList As Generic.List(Of myObject) = GetObjectsFromSomewhere()
   Dim returnList As New Generic.List(Of myObject)
   returnList = From o In FullObjectList Skip startIndex Take count
   Return returnList
End Function

Then your controller passes the returned listed to the view for display, and you loop through it, displaying the items however you please.

Hope this helps.

Ender
+1  A: 

I have no idea how StackOverflow implements it, but you don't need to use any asp.net control.

Of course you would need to build your own pager.

Take a look at the NerdDinner tutorial, it has a section showing how you can create a paged list. http://weblogs.asp.net/scottgu/archive/2009/04/28/free-asp-net-mvc-nerddinner-tutorial-now-in-html.aspx

It is pretty easy and you have full control over all the markup. In fact you pretty much have to provide all the markup almost none of the markup is generated by asp.net.

metanaito
Ahh. I never reached that chapter in this tutorial. lll give it a shot with what this tutorial says.
theraneman