Yogesh Vedpathak

Yogesh Vedpathak

  • 678
  • 1.3k
  • 179.6k

not able to make call Post Action Method on Submit button .

Mar 8 2018 5:42 AM
button code
 
<button type="submit" onclick="location.href='@Url.Action("Login", "Registration", FormMethod.Post)'" class="btn btn-default">Submit</button>
 
// Code of Get Method
[HttpGet]
public ActionResult Login()
{
return View();
}
// Code Of HttpPost Method
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(UserResgitartion objUser)
{
if (ModelState.IsValid)
{
using (MyDatabaseEntities Db = new MyDatabaseEntities())
{
var obj = Db.UserResgitartions.Where(a => a.UserName.Equals(objUser.UserName) && a.Password.Equals(objUser.Password)).FirstOrDefault();
if (obj != null)
{
Session["UserID"] = obj.UserID.ToString();
Session["USERNAME"] = obj.UserName.ToString();
if (objUser.UserName == "Admin" && objUser.Password == "admin")
{
return View("AdminDashBoard");
}
else
{
return View("UserDashBoard");
}
// return RedirectToAction("UserDashBoard");
}
}
}
return View(objUser);
}
public ActionResult UserDashBoard()
{
if (Session["UserID"] != null)
{
return View();
}
else
{
return RedirectToAction("Login");
}
}

Answers (2)