On my system we’re using ASP.NET MVC with cshtml. I have a controller that should return a view based on his name. The software was made on Portuguese so I have:
AgendamentoConfirmacaoiController -> agendamentoConfirmacao(token) -> View(agendamentoConfirmacao)
My path is:
Areas/AgendamentoSQ/view/AgendamentoConfirmacao/agendamentoConfirmacao
The Map.Route
is:
Map.Routes("AgendamentoSQ",
"AgendamentoSQ/{controller}/{action}%26{queryParams}",
queryParams = UrlParameters.Optional)
AgendamentoConfirmacaoiController
:
[HttpGet]
[Route("agendamento-confirmacao/confirmar")]
public ActionResult agendamentoConfirmacao(string token)
{
if (token.IsNullOrWhiteSpace())
{
return Json("Ação concluída", JsonRequestBehavior.AllowGet);
}
var result = AgendamentosServicoBL.confirmarAgendamento(token);
var viewModel = new ConfirmarAgendamentoForm
{
confirmacao = true,
sucesso = result.Length == 0,
mensagem = result
};
return Json("Ação concluída", JsonRequestBehavior.AllowGet);
}
View
@model WEB.Areas.AgendamentosSQ.Models.ViewModels.ConfirmarAgendamentoForm
@{
Layout = null;
}
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Confirmação de Agendamento</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.confirmation-container {
background-color: #ffffff;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
text-align: center;
padding: 40px;
max-width: 400px;
width: 100%;
}
.confirmation-icon {
font-size: 50px;
margin-bottom: 20px;
}
.confirmation-message {
font-size: 18pt;
margin-bottom: 20px;
}
.confirmation-details {
font-size: 12pt;
margin-bottom: 20px;
}
.button-link {
display: inline-block;
padding: 10px 20px;
font-size: 12pt;
font-family: Arial, helvetica, sans-serif;
color: #ffffff;
text-decoration: none;
border-radius: 5px;
}
.success {
color: #00853E;
}
.success .confirmation-icon {
color: #00853E;
}
.success .button-link {
background-color: #00853E;
}
.success .button-link:hover {
background-color: #006B2E;
}
.error {
color: #D62828;
}
.error .confirmation-icon {
color: #D62828;
}
.error .button-link {
background-color: #D62828;
}
.error .button-link:hover {
background-color: #A32020;
}
</style>
</head>
<body>
<div class="confirmation-container @(Model.sucesso ? "success" : "error")">
<div class="confirmation-icon">
@(Model.sucesso ? "✔️" : "⚠️")
</div>
<div class="confirmation-message">
@(Model.sucesso ? "Ação confirmada com sucesso!" : "Token Expirado!")
</div>
<div class="confirmation-details">
@(Model.sucesso ? (Model.confirmacao ? "Seu agendamento foi confirmado com sucesso!" : "Seu agendamento foi cancelado com sucesso!") : Model.mensagem)
</div>
<div>
@(Model.sucesso ? "" : "É necessário a confirmação do agendamento com 1 hora de antecedência ao passar disso o agendamento é CANCELADO!")
</div>
<a href="/" class="button-link">
@(Model.sucesso ? "Voltar à página inicial" : "Solicitar novo agendamento")
</a>
</div>
</body>
</html>
Routes
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
namespace WEB
{
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.MapMvcAttributeRoutes();
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
I tried to change the action hoping it would work, but nothing has worked.
I tried to check the view path and he method name but nothing…
I hope when I call the controller I receive the View with the data.
New contributor
user27393566 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
2