How to pass null in list getting error
Object reference not set to an instance of an object
on below line
usertypemv.FullName = uname.FullName;
public ActionResult AllUserTypes()
{
if (String.IsNullOrEmpty(Convert.ToString(Session["UserName"])))
{
return RedirectToAction("Login", "Home");
}
var userid = 0;
var usertypeid = 0;
int.TryParse(Convert.ToString(Session["UserID"]), out userid);
int.TryParse(Convert.ToString(Session["UserTypeID"]), out usertypeid);
if (usertypeid != 1)
{
return RedirectToAction("Admin", "DashBoard");
}
var list = new List<UserTypeMV>();
var usertype = DB.tblUserTypes.ToList();
foreach (var usertypes in usertype)
{
var usertypemv = new UserTypeMV();
usertypemv.UserTypeID = usertypes.UserTypeID;
usertypemv.UserType = usertypes.UserType;
// For Bind/Join two table
// Pass null value ??
var uname = DB.tblUsers.Find(usertypes.UserID);
usertypemv.FullName = uname.FullName;
list.Add(usertypemv);
}
return View(list);
}