1
I have this code:
@if (!string.IsNullOrWhiteSpace (Model.ErrorMessage))
{
<Script>
$ ("#ModalError').modal.('show.');
</Script>
Response.Write("<script>alert('Olá');</script>");
HttpContext.Current.Response.Write("<script>alert('Olá');</script>");
}
Where I check if Model.Error message is other than empty, so I wanted to give an alert to the user displaying the error message, but none of the way it’s in the middle of this condition if it’s working.
I’ve tried that too:
@if (!String.IsNullOrEmpty(ViewData["erro"] as string))
{
<script>alert(@ViewData["erro"]);</script>
}
This is a part of the view.
My controller is like this:
public ActionResult Login(LoginViewModel model, SignInMessage message)
{
if (!String.IsNullOrEmpty(model.ErrorMessage))
ViewData["erro"] = !String.IsNullOrEmpty(model.ErrorMessage) ? model.ErrorMessage : null;
return this.View(model);
}
Does anyone know how to solve?
You tried with @Html.Raw("<script>Alert("+ Viewdata["error"] as string +");</script>"); ?
– Leandro Angelo
I tested and nothing came up.
– Alexandre Lima
missing simple quotes @Html.Raw("<script>Alert('"+ Viewdata["error"] string +"');</script>");
– Leandro Angelo