Mirko
Mirko

Reputation: 59

Display a specific data for User

I have a problem similar to this topic http://forums.asp.net/t/1763534.aspx/1

I have to show data to customers based on their username. I do not create a new topic because I've done that long ago and nobody has responded. I ask you because you seem to know it more than others ...

This is my controller

public ActionResult Index()
{
    MembershipUser currentUser = 
        Membership.GetUser(User.Identity.Name, true /* userIsOnline */);


    ViewBag.UsersRecord = currentUser.ProviderUserKey;

    var details = from t in db.Employes
                  where t.UserId ==ViewBag.UsersRecord
                  select t;

    return View(details.ToList());

}

Strangely, Visual Studio shows me an error here

where t.UserId == ViewBag.UsersRecord

"An expression tree may not Contain dinamyc in operation"

I've done something wrong?

Upvotes: 0

Views: 1146

Answers (2)

Adam Tuliper
Adam Tuliper

Reputation: 30152

You can't use dynamic, since dynamic is determined at compile time. try:

Guid userId = (Guid)ViewBag.UsersRecord;

var details = from t in db.Employes
                  where t.UserId == userId.ToString() //if you are using a string guid, otherwise remove ToString()
                  select t;

//or simply

var details = from t in db.Employes
                  where t.UserId == (Guid)currentUser.ProviderUserKey
                  select t;

I don't know what your UserId is (type wise) so can't give you a 100% answer here

Upvotes: 2

Maciej
Maciej

Reputation: 7961

What about this:

where t.UserId == new Guid(ViewBag.UsersRecord.ToString());

Upvotes: 0

Related Questions