public ActionResult AddNewUser(int?id) { if (Session["LOGGEDIN"] != null) { objUserProperty = new User_Property(); objUserProperty.idx = Convert.ToInt32(id); objUserProperty.branchIdx = 1;//It will have the value of session branchIdx objUser = new User_BLL(objUserProperty); DataTable dtt = objUser.SelectBranch(); List <Branch_Property> BranchList = new List <Branch_Property>(); foreach (DataRow dr in dtt.Rows) { Branch_Property objbranch = new Branch_Property(); objbranch.branchName = dr["branchname"].ToString(); objbranch.idx = Convert.ToInt32(dr["idx"].ToString()); BranchList.Add(objbranch); } ViewBag.branchList = BranchList; if (id != null && id != 0) { var dt = objUser.GetById(); objUserProperty.companyIdx = 1; objUserProperty.idx = int.Parse(dt.Rows[0]["idx"].ToString()); objUserProperty.companyIdx = int.Parse(dt.Rows[0]["companyIdx"].ToString()); objUserProperty.branchIdx = int.Parse(dt.Rows[0]["branchIdx"].ToString()); objUserProperty.firstName = dt.Rows[0]["firstName"].ToString(); objUserProperty.lastName = dt.Rows[0]["lastName"].ToString(); objUserProperty.CNIC = (dt.Rows[0]["CNIC"].ToString()); objUserProperty.cellNumber = (dt.Rows[0]["cellNumber"].ToString()); objUserProperty.loginId = (dt.Rows[0]["loginId"].ToString()); objUserProperty.password = dt.Rows[0]["password"].ToString(); } return(PartialView("_AddNewUser", objUserProperty)); } else { return(RedirectToAction("Login", "Account")); } }