2
Answers

How to display en error message as "User Already exist" .

Nirupa

Nirupa

8y
307
1
I have followed your below link ...please help me out i have use same code
 
http://www.c-sharpcorner.com/UploadFile/145c93/save-password-using-salted-hashing/
 
But the error message in not displaying
 
public class AdminController : Controller
{
// GET: Admin
public ActionResult Index()
{
return View();
}
// GET: Admin/Details/5
public ActionResult Registration()
{
return View();
}
[ValidateAntiForgeryToken]
[HttpPost]
public ActionResult Registration(User objNewUser)
{
try
{
using (var context = new CmsDbContext())
{
var chkUser = (from s in context.ObjRegisterUser where s.UserName == objNewUser.UserName || s.EmailId == objNewUser.EmailId select s).FirstOrDefault();
if (chkUser == null)
{
var keyNew = Helper.GeneratePassword(10);
var password = Helper.EncodePassword(objNewUser.Password, keyNew);
objNewUser.Password = password;
objNewUser.CreateDate = DateTime.Now;
objNewUser.ModifyDate = DateTime.Now;
objNewUser.VCode = keyNew;
context.ObjRegisterUser.Add(objNewUser);
context.SaveChanges();
ModelState.Clear();
return RedirectToAction("LogIn", "Login");
}
ViewBag.ErrorMessage = "User Allredy Exixts!!!!!!!!!!";//---this message is not displaying---//
return View();
}
}
catch (Exception e)
{
ViewBag.ErrorMessage = "Some exception occured" + e;
return View();
 
 
Thanks Inadvance 
Answers (2)