I have a Model called Question:
public class Pregunta
{
public int id { get; set; }
public string descripcion { get; set; }
public int peso_id { get; set; }
public List<int> roles_id { get; set; }
public int dimension_id { get; set; }
public int amsa_id { get; set; }
public int modelo_operativo_id { get; set; }
public List<Alternativa> alternativas { get; set; }
}
And the Alternative model
public class Alternativa
{
public int id { get; set; }
public string descripcion { get; set; }
public int pregunta_id { get; set; }
public int maduracion_id { get; set; }
}
By business rule a Pregunta
can have 1 or many alternatives (5 is the limit) and I need to create an alternative form depending on the value that the user selects in an element <select>
<div class="form-group">
<label class="control-label col-md-2">Cantidad de Alternativas</label>
<div class="col-md-10">
<select class="form-control" id="cantidad_alternativas">
<option value="0" selected>Seleccione cantidad</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
To do tests I did the following:
@for (int i = 0; i < 5; i++)
{
<div class="form-group">
@Html.LabelFor(model => model.alternativas[i].descripcion, "Descripcion", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.alternativas[i].descripcion, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.alternativas[i].descripcion, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.alternativas[i].maduracion_id, "Maduracion", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.alternativas[i].maduracion_id, (SelectList)ViewBag.Maduraciones, "Seleccione Maduracion", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.alternativas[i].maduracion_id, "", new { @class = "text-danger" })
</div>
</div>
}
Problem 1
How can I delimit the end of the for cycle, with the value that the user selects in
<select>