C#
[HttpPost] public ActionResult Create(Users user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return RedirectToAction("Index"); } return View(user); }ModelState.IsValid is always false.
so it just return view and new record is not getting added..

Pooja ChowdhuryRank #3,615 · 403 reputationPosted Feb 2, 2017, 10:49 PM EST
@using (Html.BeginForm("Index", "Member", FormMethod.Post))
{
@Html.ValidationSummary(true)
@*Label to display username*@
@*Textbox for user input*@
@*Show validation error (if any) on form submission*@
@*Label for pasword*@
@*Password box for inputting password*@
@*Show validation errors(if any) on form submission*@
@ViewBag.Message
}
Pooja ChowdhuryRank #3,615 · 403 reputationPosted Feb 2, 2017, 10:50 PM EST
public ActionResult Index(MemberInfo MB)
{
if (ModelState.IsValid)
{
DBAccessLayer.DBdata objDB = new DBAccessLayer.DBdata();
if (objDB.checkUser(MB.UserName, MB.Password)) // Calls the Login class checkUser() for existence of the user in the database.
{
return View("Show", MB); // Return the "Show.cshtml" view if user is valid
}
else
{
ViewBag.Message = "Invalid Username or Password";
return View(); //return the same view with message "Invalid Username or Password"
}
}
else
{
return View();
}
}
Pooja ChowdhuryRank #3,615 · 403 reputationPosted Feb 2, 2017, 11:43 PM EST
Joginder BangerRank #360 · 7K reputationPosted Feb 2, 2017, 10:44 PM EST
Joginder BangerRank #360 · 7K reputationPosted Feb 2, 2017, 10:47 PM EST
Sandip G PatilRank #1,083 · 1.8K reputationPosted Feb 2, 2017, 11:00 PM EST
Joginder BangerRank #360 · 7K reputationPosted Feb 2, 2017, 11:29 PM EST