无法从非静态上下文中访问静态方法

时间:2015-03-27 12:37:25

标签: asp.net-mvc-4 c#-4.0

我有以下代码和平

namespace myProject.Core
{
    public class ProfileCommon : ProfileBase
    {
        public static ProfileCommon CurrentUser
        {
            get
            {
                return (ProfileCommon)ProfileBase.Create(Membership.GetUser().UserName);
            }
        }
        public static ProfileCommon GetProfile(string userName)
        {
            return (ProfileCommon)ProfileBase.Create(userName);
        }
    }
}

以下是我认为的一段代码。

           <div class="myClass">
                @{
                    string userName = Convert.ToString(HttpContext.Current.Session[Sessions.UserName]);
                    ProfileCommon Profile1 = new ProfileCommon();
                    ProfileCommon Profile = Profile1 .GetProfile(userName);
                    }
                    string displayUserName = User.Identity.Name;
                }
            </div>

但是,我在第

行收到错误
  

prf1.GetProfile(用户名);

错误是&#34; 无法在非静态环境中访问静态方法GetProfile &#34;

此错误仅发生在Visual Studio 2013中,但相同的代码可以正常使用Visual Studio 2010中的任何错误。

0 个答案:

没有答案