Reputation: 29
I'm creating some sort of survey in ASP.NET MVC and when a user fills a create form view all the values are stored in an object that will be saved in a session. At the end of the survey I want to save all the objects to the database in one action.
Email mails = new Email();
mails = Session["Emails"];
db.Emails.Add(mails);
It says:
cannot implicitly convert type Object to Namespace.models.emails.
The error occurs at this line :
mails = Session["Emails"];
Upvotes: 0
Views: 240
Reputation: 4835
Seesions in ASP.Net, by default, returns the Object
type. You have to typecast it while assigning.
Try this:
if (Session["Emails"] != null)
{
Email mails = (Email)Session["Emails"]; //Assuming Session will contain one email
db.Emails.Add(mails);
}
Upvotes: 2