public ActionResult Create(Employee Emp) { try { // TODO: Add insert logic here string Code = RandomString(12); Emp.EmployeeCode = Code; _Empdb.InsertModel(Emp); _Empdb.save(); return RedirectToAction("Index"); } private static Random random = new Random(); public static string RandomString(int length) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; return new string(Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]).ToArray()); }