Convert a Session to Boolean - Asp.net mvc?

Asked

Viewed 78 times

3

I have in my system a Session that stores an information "S" or "N"

Session["Administrador"] = retorno.ADMINISTRADOR;

In the layout I want to convert it to Boolean

@{
    bool administrador = bool.Parse(Session["Administrador"].ToString());
}

1 answer

3


Try this way:

@{
    bool administrador = Session["Administrador"].ToString() == "S";
}

or

@{
    bool administrador = Session["Administrador"].Equals("S");
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.