public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { HttpContextBase objContext = controllerContext.HttpContext; CustomerEditViewModel obj = new CustomerEditViewModel(); obj.customer.Address = new Address(); //obj.customer.CustomerDeliveryAddress = new List<CustomerDeliveryAddress>(); obj.customer.CustomerId = int.Parse(objContext.Request.Form["customer.CustomerId"]); obj.customer.LastName = objContext.Request.Form["customer.LastName"]; obj.customer.FirstName = objContext.Request.Form["customer.FirstName"]; obj.customer.CompanyName = objContext.Request.Form["customer.CompanyName"]; obj.customer.Phone = objContext.Request.Form["customer.Phone"]; obj.customer.CellPhone = objContext.Request.Form["customer.CellPhone"]; obj.customer.Email = objContext.Request.Form["customer.Email"]; obj.customer.VATNumber = objContext.Request.Form["customer.VATNumber"]; obj.customer.AccountNumber = objContext.Request.Form["customer.AccountNumber"]; obj.customer.Annotation = objContext.Request.Form["customer.Annotation"]; obj.customer.ContactName = objContext.Request.Form["customer.ContactName"]; obj.customer.ContactEmail = objContext.Request.Form["customer.ContactEmail"]; obj.customer.ContactCellPhone = objContext.Request.Form["customer.ContactCellPhone"]; obj.customer.Type = objContext.Request.Form["customer.Type"]; obj.customer.TAXLiability = objContext.Request.Form["customer.TAXLiability"]; obj.customer.Address.AddressId = int.Parse(objContext.Request.Form["customer.Address.AddressId"]); obj.customer.Address.StreetName = objContext.Request.Form["customer.Address.StreetName"]; obj.customer.Address.StreetNumber = int.Parse(objContext.Request.Form["customer.Address.StreetNumber"]); obj.customer.Address.Box = int.Parse(objContext.Request.Form["customer.Address.Box"]); obj.customer.Address.PostalCodeNumber = int.Parse(objContext.Request.Form["customer.Address.PostalCodeNumber"]); obj.customer.Address.Town = objContext.Request.Form["customer.Address.Town"]; return obj; }
// GET: Customers/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Customer customer = db.Customers.Find(id); CustomerEditViewModel cevm = new CustomerEditViewModel(); cevm.customer = customer; if (customer == null) { return HttpNotFound(); } return View(cevm); }