public ActionResult Create(FormCollection collection) { int? TypeOfDevice = collection["TypeOfDevice"].Equals("0") ? (int?)null : Convert.ToInt32(collection["TypeOfDevice"]); string DeviceCode = collection["DeviceCode"]; string NewCode = collection["NewCode"]; string DeviceName = collection["DeviceName"]; double Price = collection["Price"].Equals("") ? 0 : Convert.ToDouble(collection["Price"]); // Price = (Price1.ToString().Replace(",", "")); string Configuration = collection["Configuration"]; string Notes = collection["Notesdv"]; int? SupplierId = collection["SupplierId"].Equals("0") ? (int?)null : Convert.ToInt32(collection["SupplierId"]); int? Status = Convert.ToInt32(collection["Status"]); int? Project = collection["ProjectDKC"].Equals("0") ? (int?)null : Convert.ToInt32(collection["ProjectDKC"]); string PurchaseContract = collection["PurchaseContract"]; DateTime?DateOfPurchase = collection["DateOfPurchase"].Equals("") ? (DateTime?)null : Convert.ToDateTime(collection["DateOfPurchase"]); DateTime?Guarantee = collection["Guarantee"].Equals("") ? (DateTime?)null : Convert.ToDateTime(collection["Guarantee"]); int? UserId = collection["UserId"].Equals("0") ? (int?)null : Convert.ToInt32(collection["UserId"]); // int? ParentId = collection["ParentId"].Equals("0") ? (int?)null : Convert.ToInt32(collection["ParentId"]); data.AddDevice(DeviceCode, null, DeviceName, TypeOfDevice, null, Configuration, Price, PurchaseContract, DateOfPurchase, SupplierId, Project, Guarantee, Notes, UserId, Status); var DeviceId = data.Devices.Where(x => x.DeviceCode == DeviceCode).Single().Id; int DeviceId1 = Convert.ToInt32(DeviceId); return(RedirectToAction("EditDevice", "Device", new { Id = DeviceId1 })); // return RedirectToAction("Device", "Device"); }