I'm trying to pass a value from Controller
to View
, here's how it's in View:
<div class="alert alert-danger alert-dismissable" role="alert" id="alerta">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
@Html.Raw(ViewBag.Mensagem)
@ViewBag.Mensagem
@Model.Message
</div>
And here's how it's in the controller:
if (cod != null && msgm != null)
{
ViewData["Mensagem"] = "Código: " + cod + ". Erro: " + msgm;
obj.model.Message = "Código: " + cod + ". Erro: " + msgm;
ViewBag.Mensagem = "Código: " + cod + ". Erro: " + msgm;
return View(obj.model);
}
But neither of you gets the values, it always goes blank, as if you did not get anything. I do not know why it happens, I was using ajax to show the alert, I thought it might be that, but I always keep it visible, and so does the problem.
I've tried going through ViewBag
, ViewData
and even the same variable, none of them.