Developer forum

Forum » Templates » Looping form fields (Forms module)

Looping form fields (Forms module)

Søren Mastrup
Reply

I want to loop through all options in a select field.

I am trying the following:

@{
    var form = GetLoop("Fields");
}
@foreach(var field in form){
    <select class="form-control">
        @foreach(var option in field.GetLoop("Fields")){
            <option value="">My field</option>
        }
    </select>
}

The code outputs the select box, but my options doesn't show. How do I loop my option fields?


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Søren

You might want to change @foreach(var option in field.GetLoop("Fields")){ to @foreach(var option in field.GetLoop("Options")){

Votes for this answer: 1

 

You must be logged in to post in the forum