public ActionResult Create(ContainerType containertype) { if (ModelState.IsValid) { var query = (from t in db.ContainerTypes where t.ContainerType1 == containertype.ContainerType1 select t).ToList(); if (query.Count > 0) { ViewBag.SuccessMsg = "Container name is already exist"; return(View()); } containertype.ContainerTypeID = sourceModelobject.GetMaxNumberContainer(); db.ContainerTypes.Add(containertype); db.SaveChanges(); ViewBag.SuccessMsg = "You have successfully added Container Type."; return(View("Index", db.ContainerTypes.ToList())); } return(View(containertype)); }