我目前在 asp.net mvc4 工作。并实施用户资料信息。我的控制器即HomeController包含;
public ActionResult Resume()
{
using (ProfileInfo profile = new ProfileInfo())
{
return View(profile.ProfileGetInfoForCurrentUser());
}
}
我的profileinfo类包含一个返回类型为“ResumeViewModel”的方法;
public ResumeViewModel ProfileGetInfoForCurrentUser()
{
ProfileBase profile = ProfileBase.Create(Membership.GetUser().UserName);
ResumeViewModel resume = new ResumeViewModel();
resume.Email = Membership.GetUser().Email.ToString();
resume.FullName = Membership.GetUser().UserName;
return resume;
}
现在我的ResumeViewModel看起来像这样;
public class ResumeViewModel
{
public string FullName { get; set; }
public string Email { get; set; }
}
虽然我的观点是强烈的'@model PortfolioMVC4.Models.ResumeViewModel'
. 但是,当我运行它时,出现以下错误;
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
{
Line 14: ProfileBase profile = ProfileBase.Create(Membership.GetUser().UserName);
Line 15: ResumeViewModel resume = new ResumeViewModel();
Line 16: resume.Email = Membership.GetUser().Email.ToString();
Line 17: resume.FullName = Membership.GetUser().UserName;
我在第 15 行遇到错误;这基本上是 ProfileGetInfoForCurrentUser 方法中存在的代码(如上所示)。我不知道该怎么办?对此的任何帮助都是值得赞赏的;