2
I have a question and hope that someone can help me. I am not being able to send objects from my View to the controller. Every time it comes, it’s empty. I’ve tried a lot of things and I can’t seem to.
This is the Controller
public ActionResult PersistirValoresMetricas(List<ModeloAtualizacaoMetrica> modelo)
{
return View();
}
Here is the View that is filled by the user, note that only the Field Valor needs to be filled in, the others already coming filled in.
@model IEnumerable<SigeApp.Models.ModeloAtualizacaoMetrica>
@using (Html.BeginForm("PersistirValoresMetricas", "Administracao",
FormMethod.Post))
{
<table class="table">
<tr>
<th> Nome </th>
<th> Mes </th>
<th> Ano </th>
<th> Valor </th>
</tr>
@foreach (var item in Model)
{
<tr>
<td style="display:none"><input type="text" value="@item.Id_Metrica" name="Id_Metrica"></td>
<td style="display:none"><input type="text" value="@item.Mes" name="Mes" ></td>
<td style="display:none"><input type="text" value="@item.Ano" name="Ano"></td>
<td style="display:none"><input type="text" value="@item.Id_Planejamento" name="Id_Planejamento" ></td>
<td>@Html.DisplayFor(x => item.TBMETRICA.Nome)</td>
<td>@Html.DisplayFor(x => item.Mes)</td>
<td>@Html.DisplayFor(x => item.Ano)</td>
<td><input type="text" class="form-control" name="Valor" /></td>
</tr>
}
<tr>
<td>
<input type="submit" value="Atualizar" class="btn btn-success" />
</td>
</tr>
</table>
}
And this is the model that should arrive in the controller, it happens that it can occur of arriving more than one, for I had the idea of putting as parameter in the controller a List of that object
public class ModeloAtualizacaoMetrica
{
public int Id_Metrica { get; set; }
public int Mes { get; set; }
public int Ano { get; set; }
public decimal Valor { get; set; }
public int Id_Planejamento { get; set; }
public virtual TBMETRICA TBMETRICA { get; set; }
public virtual TBPLANEJAMENTO TBPLANEJAMENTO { get; set; }
}
I appreciate the help.
It worked perfectly, thank you. =)
– Jhony Adell