2
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>
Receives the id to search the record:
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 to make the query User registration() :
        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 />
						
tbuscar.Listarporid(id); it returns something, since it was not assigned to any variable?
– user46523
yes, return, I will add the User Registration Code
– Harry
@model IEnumerable<Generico.Dominio.TB_USUARIO>change to@model Generico.Dominio.TB_USUARIOand on the linetbuscar.ListarPorID(id)put in front aTB_USUARIO us = tbuscar.ListarPorID(id)and in thereturn View(tbuscar);swap forreturn View(us);– user46523
John, your answer is correct, you can post the answer so you can mark. I appreciate the help!
– Harry
I was happier that you solve your problems already put the answer then delete here and the other comments.
– user46523