I am getting this error:
An object reference is required for the non-static field, method, or property 'System.Web.Security.MembershipProvider.GetUserNameByEmail(string)
When trying to use the code:
string userName = MembershipProvider.GetUserNameByEmail(email);
From my controller:
[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
}
}
}
I do not understand why I am getting the error as I have found examples of this code being used and cannot see the difference?