3
Hi, I’m new to c# 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 one @if
to check if my ViewData
is null, if not want to display the message, further by what I see the ViewData
does not contain the phrase I designated in the controller.
Thank you.
In addition, this link explains the differences between viewData, tempData :)) http://www.macoratti.net/15/06/mvc_conc1.htm
– Brunno
Thanks, very good article, I’ll take a look
– Danilo Pádua