Why would = ViewData [""] show a row, but could not evaluate it for the same row?

//CHECK IF WE SHOULD SHOW THE PASSWORD HINT OR NOT
Setting passwordhints;

using (var db = new dbDataContext())
{
    passwordhints = (from c in db.Settings
            where c.Name == "ShowPasswordHints" && c.ID == _ID
            select c).FirstOrDefault();
}

if (passwordhints != null)
    //NOTE: .Value IS A STRING
    ViewData["ShowPasswordHints"] = passwordhints.Value;
else
    ViewData["ShowPasswordHints"] = "False";

//END PASSWORD HINTS CHECK

is in the controller, when I get to the page itself, I output

<%=ViewData["ShowPasswordHints"]%> in the title tag, and I see it where it says “True” (without the quotes, I also checked the spaces by surrounding it with a bracket, and there are no spaces literally just True)

However when i do

<%if(ViewData["ShowPasswordHints"] == "True") {%> SHOW THIS <%}%>

SHOW IT never appears, what the hell?

The UPDATE . However, if ViewData is set like this: IT WORKS ... HUH ??

if (accountRepository.isLDAPEnabled(_ID))
                ViewData["LDAP"] = "True";
            else
                ViewData["LDAP"] = "False";

view...

<%if(ViewData["LDAP"] == "True"){ %>
           SHOW THIS
         <%} %>

THANKS EVERYONE HERE IS A NEW METHOD WHICH WORKS BIG

ViewData["something"] = true;

<%if(true.Equals(ViewData["something"])){%> SHOW THIS <%}%>
+5
source share
1 answer

ViewData IDictionary<string, object>, ViewData["ShowPasswordHints"] object. object . . , string, :

<%if((string)ViewData["ShowPasswordHints"] == "True") {%> SHOW THIS <%}%>

msdn.

UPDATE: , ViewData["ShowPasswordHints"], . , # , , , , - ​​ , , ViewData IDictionary<string, object> ( ). , string, , , . (, , ViewData - MVC, )

<title>, <%= %> ToString() . ViewData["ShowPasswordHints"] - , , - ToString() - .

: ?

+9

All Articles