Warning: mysqli_query(): (HY000/1021): Disk full (/tmp/#sql-a2c-1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device") in /var/www/html/wp-includes/wp-db.php on line 2024

Warning: mysqli_query(): (HY000/1021): Disk full (/tmp/#sql-a2c-1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device") in /var/www/html/wp-includes/wp-db.php on line 2024
class="post-443772 post type-post status-publish format-standard hentry" id="post-443772">

Accessing ViewBag variables in View

Finally giving up on asking the Google Gods…

I’m trying to access ViewBag variables in my view from the query below.

using (var context = new PrincipalContext(ContextType.Domain))
{
    var un = UserPrincipal.FindByIdentity(context, User.Identity.Name);
    var userinfo = db.Users
                     .Where(x => x.sAMAccountName == un.SamAccountName)
                     .Select(x => new
                      {
                          x.sAMAccountName,
                          x.Id
                      }).First();

    ViewBag.UserInfo = userinfo;
}

I see the variables in VS’ breakpoint watcher

enter image description here

However, when I try to access them:

enter image description here

enter image description here

Not 100% certain on how I’m supposed to be accessing these? I don’t want to iterate through them because they’re getting placed in a form as fields. As previously mentioned, the Google Gods were less than helpful.
Thanks!

UPDATE

I took a closer look based on the responses received, regarding casting. Ultimately what I ended up doing was retrieving the entire model and returning that in the ViewBag, and accessing it as such:

using (var context = new PrincipalContext(ContextType.Domain))
{
     var un = UserPrincipal.FindByIdentity(context, User.Identity.Name);
     User info = new User();
     info = (User)db.Users
                .Where(x => x.sAMAccountName == un.SamAccountName)
                .First();
      ViewBag.User = info;

}

And then in the view

@ViewBag.User.Id
@ViewBag.User.sAMAccountName

Ultimately I was looking to access these variables without iterating over them in a loop. When I add a select statement into my query, it begins to complain that I’m trying to cast anonymous strings to a model object. Is one able to retrieve select data from a model in ASP, or do you need to return an entire model set? Now it’s just curiosity.
Thank you for the guidance!

Leave a Reply

Your email address will not be published. Required fields are marked *