传递参数时出错

时间:2011-07-14 12:23:20

标签: c#

我有一个UserBll类,它有以下方法

public string GetaspnetUserIdByUserName(string name )
{
    string _lsttUserId = (from aspnet in db.aspnet_Users
                            where aspnet.UserName.Equals(name)
                            select aspnet.UserId
                         ).ToString();
    return _lsttUserId;
}

我创建了一个具有UserId和UserName字段的Usertable实例,我正在使用以下代码

UserBLL bll = new UserBL
UserTable uTable = new UserTable();
uTable.UserId = bll.GetaspnetUserIdByUserName(Membership.GetUser(model.UserName));

在上面的代码中我得到以下错误:

  

GetaspnetUserIdByUserName有一些无效的参数

有人可以告诉我我在做什么错误

3 个答案:

答案 0 :(得分:1)

Membership.GetUser不会返回字符串,而是返回MembershipUser

你想:

string username = Membership.GetUser(model.UserName).UserName;

如果您想了解最新情况:

MembershipUser theUser = Membership.GetUser(model.UserName);
string userName = theUser.UserName;

答案 1 :(得分:1)

我认为你的意思是调用这样的函数:

UserBLL bll = new UserBL
UserTable uTable = new UserTable();
uTable.UserId = bll.GetaspnetUserIdByUserName(model.UserName);

假设model.UserNamestring值。

答案 2 :(得分:1)

BLL功能是不必要的。

MembershipUser user = Membership.GetUser("{your desired user name}");
UserTable uTable = new UserTable();
uTable.UserId = user.ProviderUserKey.ToString();

因为MembershipUser.ProviderUserKey == aspnet_User.UserId