tags:

views:

87

answers:

5

I am used to using a Repeater control in conventional ASP.Net web projects. I see ASP.Net MVC doesn't have this sort of thing. What should I be using here?

EDIT:

In response to the question, what am I trying to do that I can't achieve in the foreach. I guess I am trying to get a alternating row style. Also, it just feels somewhat wrong to have stuff other than markup in the view. But maybe I will get over that as I work with it. Thanks for the answers.

+8  A: 

The simplest thing to use is a foreach loop.
What are you trying to do?

EDIT:

<%  bool odd = false;
    foreach(var row in something) { %>
    <tr class="<%= odd ? "OddRow" : "EvenRow" %>">
        ...
    </tr>
<% odd = !odd; } %>
SLaks
+1 My thoughts exactly. There are no controls like we had in non MVC.
Dustin Laine
I miss the alternate item template the most i guess.
uriDium
You can flip a boolean and use the ternary operator inline, which is actually much easier than duplicating the entire template.
SLaks
I always used this technique even in repeaters (using Container.ItemIndex % 2). A much more elegant solution than copy / pasting code into an alternating template IMO.
richeym
+1  A: 

To add to SLaks response.

You could encapsulate your html into a Partial View.

Call <%= Html.Partial("ViewName", optional_ViewModel) %>.

This might feel closer to the repeater control. Where the PartialView would be sort of like your item template.

This approach also lends itself to code reuse very nicely.

zznq
+1  A: 

If you miss a lot of the features of WebForms, maybe you just need a richer view engine? Might I suggest the Spark View Engine? Like WebForms, there's lots of functionality included so you don't have to keep rewriting the same stuff and/or write a bunch of your own helpers.

mgroves
The Spark ViewEngine is very powerful and I definitely like it better than the tag-soup that generally is produced when working with the WebForms ViewEngine...
Redbeard 0x0A
A: 

alternating row style can be achieved by css styles ...
BTW - each one funcionality from web forms can be achieved in mvc ... in the end all is html, js and css

Jack
A: 

You could even create an HTML helper for this.

Carles