현재 사용자 ID를 저장할 때 Create
내 게시물에서이 오류가 발생합니다.System.NullReferenceException : '개체 참조가 개체의 인스턴스로 설정되지 않았습니다. MVC5
지침, 조언, 솔루션에 대한 링크가 큰 help.Thanks
이 될 것입니다 모든포스트 Class.cs 내가 currentUserId가 null이 아닌지 확인해야로서 컨트롤러
에서
public class Post
{
public virtual ApplicationUser PostMaker { get; set; }
}
public ActionResult Create(Post post, HttpPostedFileBase upload)
{
string currentUserId = User.Identity.GetUserId();
Post postObje = new Post();
postObje = post;
ApplicationUser postMaker = db.Users.Find(currentUserId);
if (ModelState.IsValid)
{
postObje.PostMaker.Id = currentUserId; //(Error is in this line)
db.Post.Add(postObje);
db.SaveChanges();
}
}
이렇게하면 로그인 했습니까? –
오류 이미지의 모양과 함께, 그것은 당신이 이미지에 "}"를 닫고 "{"컨트롤러 위의 "postObje.PostMaker.Id = currentUserId"를 가지고 있기 때문에 다른 클래스/컨트롤러/; " –