我收到此错误:
非静态字段、方法或属性 'System.Web.Security.MembershipProvider.GetUserNameByEmail(string) 需要对象引用
尝试使用代码时:
string userName = MembershipProvider.GetUserNameByEmail(email);
从我的控制器:
[HttpPost]
public ActionResult ChangeEmail(ChangeEmailViewModel model)
{
if (ModelState.IsValid)
{
string email = model.Email;
string userName = MembershipProvider.GetUserNameByEmail(email);
if (userName != null)
{
// change email
}
else
{
// don't allow email change as that email is already in use
}
}
}
我不明白为什么我会收到错误,因为我找到了正在使用此代码的示例并且看不到差异?