public ActionResult Create([Bind(Include = "id,ServerName,HostName,Date,PrimaryIP,SecondaryIP,Description,VLAN,Gateway,LocationId,UnitId,HostId,Environment,")] InventoryViewModel ivm) { CYBInfrastrctureContext db = new CYBInfrastrctureContext(); bool Create = db.Inventories.Any(x => x.ServerName == ivm.ServerName && x.Id != ivm.Id); if (Create == true) { //TempData["Success"] = "Server already exists, Try another one"; //ViewBag.message= "Server already exists, Try another one"; ModelState.AddModelError("SeverName", "Server already exists, Try another one"); } if (ModelState.IsValid) { var invent = new Inventory { Id = ivm.Id, ServerName = ivm.ServerName, HostName = ivm.HostName, PrimaryIP = ivm.PrimaryIP, SecondaryIP = ivm.SecondaryIP, Description = ivm.Description, VLAN = ivm.VLAN, Gateway = ivm.Gateway, LocationId = ivm.LocationId, UnitId = ivm.UnitId, HostId = ivm.HostId, Environment = ivm.Environments, Date = ivm.Date //ServerType=ivm.ServerTypes, }; _InventoryManager.Add(invent); _InventoryManager.SaveChanges(); TempData["Success"] = "Added Successfully!"; return(RedirectToAction("Index")); } //var location = _locationManager.GetAll().ToList(); //var unit = _unitManager.GetAll().ToList(); //InventoryViewModel inventorymodel = new InventoryViewModel //{ // Locations = location, // Units = unit //}; return(View(ivm)); }