I have the structure:
Page where I select the record for editing:
@if (Model.Count() > 0)
{
foreach (var item in Model)
{
<tr>
<td>@item.NOME</td>
<td>@item.LOGIN</td>
<td>@item.ADMINISTRADOR</td>
<td><a href="/CadastroUsuario/AlteraRegistro/@item.IDUSUARIO" class="btn btn-primary btn-block">ALTERAR</a></td>
<td><a href="/CadastroUsuario/ExcluirRegistro/@item.IDUSUARIO" class="btn btn-danger btn-block">EXCLUIR</a></td>
</tr>
}
}
</div>
Get the id to search the registry:
public ActionResult AlteraRegistro(int id)
{
if (Session["id"] == null)
{
return RedirectToAction("Index", "Home");
}
try
{
var tbuscar = new CadastroUsuarioAplicacao();
tbuscar.ListarPorID(id);
return View(tbuscar);
}
catch (Exception)
{
TempData["Erro"] = "Erro ao Alterar Registro.";
return RedirectToAction("ListarRegistro", "CadastroUsuario");
}
}
Code for the query User Registration Application ():
public TB_USUARIO ListarPorID(int id)
{
var strQuery = string.Format("select * from tb_usuario where IDUSUARIO = '{0}' ", id);
using (contexto = new Contexto())
{
var retornoDataReader = contexto.ExecutaComandoComRetorno(strQuery);
return TransformaReaderEmListaObjetos(retornoDataReader).FirstOrDefault();
}
}
Page to show the record for editing:
@model IEnumerable<Generico.Dominio.TB_USUARIO>
@{
ViewBag.Title = "Index";
}
@Html.Partial("_navbarInterno")
<br />
@Html.Partial("_PartialMensagens")
<br />