I have a table that is populated by a Model
in HTML Razor in a partialView
, a field of this table I left as editable using @Html.TextBoxFor
. After the user edit this field I need to update in the DB, but first I need to retrieve the changed value.
How can I go through the table and get this value in Controller
?
Here is the code for 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
}