I have Customer class
public class Customer
{
public string Name { get; set; }
public string Surname{ get; set; }
public string Email { get; set; }
public string MobilePhone { get; set; }
public int Type { get; set; }
}
In Index method of HomeController, I have created an instance of Customer and set values to properties.Then I stored it in session to get the object in Index(HttpPost) method which is in the same controller. In Index(HttpPost) method, I can get all the property values properly except 'Type' Property. When I get Customer object from session, 'Type' property of this object is always equal to 0.
public ActionResult Index(string id, string co)
{
Customer cust = new Customer();
cust.Name = "customer";
cust.Surname = "test";
cust.EMail = "[email protected]";
cust.Type=2;
Session["customer"] = cust;
return View(customer);
}
[HttpPost]
public ActionResult Index()
{
Customer customer = new Customer();
if (Session["customer"] != null)
{
customer = (Customer)Session["customer"];
}
//customer.Type is equal 0
}
What could be the reason and how can it be avoided?
Thanks for replies in advance
Session["customer"]was notnull? Because if it was then you'll have that initialCustomerthat you created with all default values set to it's properties.