2
I have a table that is filled by a Model
in HTML Razor in a partialView
, a field of that table I left as editable using the @Html.TextBoxFor
. After the user edit this field need to update in DB, but first need to recover the changed value.
How can I go through the table and get this value on Controller
?
Follow the code of the page:
<table id="tblLivros" class="table table-hover table-striped" cellspacing="0" style="width: 100%;">
<thead>
<tr>
<th>Livro</th>
<th>Valor</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Livro)
</td>
<td>
@Html.TextBoxFor(modelItem => item.Valor, new { style = "width: 50px;"})
</td>
</tr>
}
</tbody>
</table>
<div class="form-actions text-right pal">
<button type="submit" class="btn btn-primary" name="Salvar" value="Salvar">
Salvar Alterações
</button>
</div>
And of Controller
:
[HttpPost]
public ActionResult Salvar(ViewModel Livros)
{
//Percorrer a tabela
}
Can you please enter the code for Viewmodel in your question?
– Leonel Sanches da Silva