-1
I have a form that receives data from the client interested in acquiring a loan, when he clicks on simulating the program does the simulation and records in the database, until then it works well. However I need to display the details of this simulation on another page. I have tried redirecting with the "return RedirectToAction("Details", idsimulacao);"
but I was unsuccessful...
Follows code:
Create:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Nome,Cpf,ValorDesejado,ValorParcela,Telefone,ConvenioID,ProdutoID,DataSimulacao,ContratacaoID,Dispensada,Rg,Endereco,Numero,Bairro,Cep,Agencia,Conta,TipoConta,UrlDocFrente,UrlDocVerso,UrlSelfie")] Simulacao simulacao)
{
if (ModelState.IsValid)
{
_context.Add(simulacao);
await _context.SaveChangesAsync();
CalcularValorParcela(simulacao.Id, simulacao.ProdutoID, simulacao);
idsimulacao = simulacao.Id;
_context.Update(simulacao);
await _context.SaveChangesAsync();
return RedirectToAction("Details", idsimulacao);
}
ViewData["ConvenioID"] = new SelectList(_context.Convenio, "Id", "Nome", simulacao.ConvenioID);
ViewData["ProdutoID"] = new SelectList(_context.Produtos, "Id", "Nome", simulacao.ProdutoID);
return RedirectToAction("Details", idsimulacao);
}
Details
public async Task<IActionResult> Details(int id)
{
if (id == null)
{
return NotFound();
}
var simulacao = await _context.Simulacao
.Include(s => s.Convenio)
.Include(s => s.Produto)
.FirstOrDefaultAsync(m => m.Id == id);
if (simulacao == null)
{
return NotFound();
}
return View();
}
The Redirecttoaction method did not return anything, so I started using the method:
RedirectToRoute(new { controller = "Simulacaos", action = "Details", id = simulacao.Id });
and he returned the was necessary.– Jucileudo Lima