Sourabh Dhiman

Sourabh Dhiman

  • 1.7k
  • 188
  • 6.2k

Error in a code.

Mar 26 2020 6:39 AM
public ActionResult Login(string EmailId, string Password, AdminMaster U)
{
FanzdbEntities _db = new FanzdbEntities();
AdminMaster Obj_AdminMaster = new AdminMaster();
HttpCookie cookie = new HttpCookie("user");
try
{
if (ModelState.IsValid == true)
{
if (U.RememberMe == true)
{
cookie["FirstName"] = U.EmailId;
cookie["Password"] = U.Password;
cookie.Expires = DateTime.Now.AddMinutes(5);
HttpContext.Response.Cookies.Add(cookie);
}
else
{
cookie.Expires = DateTime.Now.AddDays(-1);
HttpContext.Response.Cookies.Add(cookie);
}
}
AdminMaster obj_AdminMaster = _db.AdminMasters.Where(ad => ad.EmailId == EmailId && ad.Password == Password).FirstOrDefault();
if (obj_AdminMaster != null)
{
// return View("AllUsers","UserManagement");
Session["FirstName"] = obj_AdminMaster.FirstName;
Session["AdminId"] = obj_AdminMaster.AdminId;
return Json(new { status = true });
//return RedirectToAction("AllUsers","UserManagement");
}
else
{
return Json(new { status = false });
}
}
catch (Exception ex)
{
return Json(new { status = false });
}
}
It's me login code and remeberme code.
<script type="text/javascript">
//$(document).ready(function () {
$('#btnAdminLogin').click(function () {
var EmailId = $("#txtEmailId"),
RememberMe = $("#exampleCheck1"),
Password = $("#txtPassword");
if ($('#txtEmailId').val() == "" || $('#txtPassword').val() == "" || $('#lblRemeber').val()) {
alert("Please fill all required fields");
return false;
}
else {
$.ajax({
url: 'Login/Login',
type: 'Post',
dataType: 'json',
data: { "EmailId": $('#txtEmailId').val(), "Password": $('#txtPassword').val(), /*"RememberMe": $('#exampleCheck1').val()*/ },
success: function (data) {
var status = data.status;
if (status == true) {
var url = "/UserManagement/AllUsers";
window.location.href = url;
}
else {
alert("wrong credentials");
return false;
}
},
failure: function (data) {
alert("Something went wrong");
}
});
}
});
</script>
It's jquery code. I want check a checkbox and click login button not a store value in cookies. Please solve my error.
Jquery code. 
 
 
 

Brought to you by:

Answers (1)