2012-02-20 75 views
0

我有类似这样的主题http://forums.asp.net/t/1763534.aspx/1显示特定数据为用户

我必须表明数据基于他们的用户名客户的问题。我没有创造一个新的话题,因为我很久以前就已经完成了,没有人回复。我问你,因为你似乎知道它比其他人更...

这是我的控制器

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()); 

} 

奇怪的是,Visual Studio中显示我在这里一个错误

where t.UserId == ViewBag.UsersRecord 

“的表达树可能不包含dinamyc在操作中“

我已经做了一些事恩错了吗?

+1

抱歉,对于stackoverflow是新的,我知道他必须每次都这样做。我拿了我所有的答案,应该没问题。 – Mirko 2012-03-12 09:50:11

+0

没关系 - 只是想向你指出这一点 - 当你开始SO时并不明显。你做得很好 - 享受吧! – 2012-03-12 09:54:19

回答

2

您不能使用动态,因为动态是在编译时确定的。 尝试:

 
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; 

我不知道你的用户ID是什么(类型明智的),所以不能给你一个100%的答案在这里

+0

UserId我是一个GUID类型。我需要与UserId Employe ID进行比较,以仅显示具有相同ID的数据。 – Mirko 2012-02-21 05:17:01

+0

好的,在这种情况下看到上面的第二种情况(我编辑) – 2012-02-21 17:07:01

0

这个怎么样:

where t.UserId == new Guid(ViewBag.UsersRecord.ToString()); 
相关问题