I have the following problem when rendering some input checkbox
, I go through a loop for
with a model type List<>
as in the following example:
@for (int i = 0; i < Model.MiModeloList.Count(); i++)
{
if (Model.MiModeloList[i].Num == 1 || Model.MiModeloList[i].Num == 2 || Model.MiModeloList[i].Num == 3)
{
<div class="col-12 col-sm-6 col-md-3 li">
@Html.HiddenFor(m => m.MiModeloList[i].Num)
@Html.HiddenFor(m => m.MiModeloList[i].Nom)
<label>
@Html.CheckBoxFor(m => m.MiModeloList[i].IsSelected)
<span class="title">@Model.MiModeloList[i].Nom</span>
</label>
</div>
}
}
And the inputs that I need are rendered, but at the moment of giving f5
on the page, the same inputs are rendered again, apart from the ones I had already rendered for the first time, making me believe every time I updated the page. the same inputs again.
How can I avoid this? Will it work with a foreach
? ' So that only once I can render the inputs in the view and when I update it on the page, I do not render the same inputs, so instead of 3 I end up having n inputs ...
In the action controller, all I do is return what this method returns. The method of action is GET
private static MiModelo model = new MiModelo();
private static MiModelo MiMetodo()
{
model.MiModeloList.Add(new MiModelo.Modelo() { Cod = (int)Enums.Files.DepositoPlazo, Nom = Enums.File.DepositoPlazo.GetDescription() });
model.MiModeloList.Add(new MiModelo.Modelo() { Cod = (int)Enums.Files.AhorroEducacion, Nom = Enums.File.AhorroEducacion.GetDescription() });
return model;
}