DEBESH ROY

DEBESH ROY

  • NA
  • 13
  • 1.5k

Object reference not set to an instance of an object

Oct 5 2017 4:42 AM
I am getting this error as I am trying to display user details from sql server after login 
This is my action method:
public ActionResult ViewProfile(string id)
{
var user = db.user1.SingleOrDefault(u => u.UserName == id);
return View(user);
}
 
My .cshtml  view:
UserID:@Model.UserID 
UserName:@Model.UserName
UserEmail:@Model.UserEmail
I am getting the error "Object reference not set to an instance of an object" in this view
 
This is my link in view clicking on which i can view user profile: 
@Html.ActionLink("Profile", "ViewProfile", "Home", new { id = User.Identity.Name})
 
My Model: 
public partial class user1
{
public int UserID { get; set; }
public string UserEmail { get; set; }
public string UserName { get; set; }
public string UserPassword { get; set; }
 This model is derived from sql server
Please help 

Answers (3)