I have a login page and I tried storing some data in my sessions but when I run the project it gives me this error as you see in screenshots:
I tried to debug my code as you see in screenshot and its show me Both No_ and E_mail is null even though I checked my database and those columns. No_ and E_mail both have data:

The Code in Controller:
[HttpPost]
public ActionResult Login(string Mail)
{
using (DataContext db = new DataContext())
{
ED_data_A_S_Contact con = new ED_data_A_S_Contact();
ED_data_A_S_Contact_Business_Relation cb = new ED_data_A_S_Contact_Business_Relation();
var user = from cbr in db.Contact_Business_Relation
join c in db.Contact
on cbr.Contact_No_ equals c.Company_No_ into f
from c in f.DefaultIfEmpty()
//where c.E_Mail == Mail
select new
{
Mail = c.E_Mail
};
if (user != null)
{
Session["No_"] = cb.No_.ToString();
Session["Email"] = con.E_Mail.ToString();
FormsAuthentication.SetAuthCookie(Mail, false);
return RedirectToAction("Index");
}
else
{
ModelState.AddModelError("", "Kunde nr er ikke gyldig");
}
}
return View();
}
public ActionResult LoggedIn()
{
if (Session["No_"] != null)
{
return View();
}
else
{
return RedirectToAction("Login");
}
}
Contact_Business_Relation :
public string No_ { get; set; }
Contact:
public string E_Mail { get; set; }
The Code in view:
@model ED_data_A_S_Contact
<div class="login-wrap">
<div class="login-html">
<input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">Log ind</label>
<input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab"></label>
<form class="login-form" method="POST" enctype="multipart/form-data" action="/Account/Login/">
@*@Html.AntiForgeryToken()*@
<div class="sign-in-htm">
<div class="group">
<label for="No_" class="label">Kunde ID</label>
<input style="color:black;" id="Email" name="Mail" value="" required="" type="email" placeholder="Kunde ID ..." class="input">
<button style="float: right;margin-top: -36px; background: transparent; border: none;margin-right: 11px;" type="button" id="eye">
<img src="https://cdn0.iconfinder.com/data/icons/feather/96/eye-16.png" alt="eye" />
</button>
@*@Html.ValidationMessageFor(u => u.CustomerID)*@
</div>
<div class="group">
<input type="submit" class="button" value="Log på">
</div>
<span style="color:#dadada">@*@Html.ValidationSummary(true)*@</span>
<div class="hr"></div>
<div class="foot-lnk">
<a target="_blank" href="#">Problem med login?</a>
</div>
</div>
</form>
</div>
</div>
Can anyone direct me in the right direction? thx
cbobject fields with anything, you just create it withnew, and it seems the default constructor does not do anything with the fields either. You are not loading data for that object from the databasecbis null.