Hello, I'm new to the C # language and would like to know why my ViewData ["ErrorMessage"] does not appear in my view.
Controller:
ViewData["ErrorMessage"] = "O e-mail digitado já se encontra registrado em nossa base de dados.";
return RedirectToAction("Index","Home");
View:
<form asp-controller="Account" asp-action="Visitante" method="post" class="form-horizontal" role="form">
@if (ViewData["ErrorMessage"] != null)
{
@ViewData["ErrorMessage"];
<br />
}
<div asp-validation-summary="ValidationSummary.All" class="text-danger"></div>
<div class="form-group">
<div class="col-md-6">
<input asp-for="Nome" class="form-control" placeholder="Nome" />
<span asp-validation-for="Nome" class="text-danger"></span>
</div>
<div class="col-md-6">
<input asp-for="Sobrenome" class="form-control" placeholder="Sobrenome" />
<span asp-validation-for="Sobrenome" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input asp-for="Email" class="form-control" placeholder="E-Mail" />
<span asp-validation-for="Email" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="submit" class="btn btn-default" style="width: 100%" value="Cadastre-se agora!" data-toggle="tooltip" data-placement="bottom" data-original-title="Cadastre-se" />
</div>
</div>
</form>
See that in my view I make a @if
to check if my ViewData
is null, if not I want it to display the message, but from what I see ViewData
does not contain the phrase I assigned no controller.
Thank you.