I am having this error inside my [httpget] controller
usr.LastLoggedDate = HttpContext.Session.GetString("logg"));
cannot implicitly convert type string to system.datetime
I declared the http context set session inside the login controller
var dt = LastLoggedDate.ToString("MM/dd/yyyy");
HttpContext.Session.SetString("Logg", dt);
usr.LastLoggedDate = LastLoggedDate;
MY CODE
namespace Feed100.Controllers
{
public class UserDetailController : Controller
{
//UserDetailDataManagement objBL = new UserDetailDataManagement();
UserDetailDataManagement objBL = new UserDetailDataManagement();
public ActionResult Index()
{
return View();
}
[HttpGet]
public IActionResult Create()
{
UserDetail usr = new UserDetail();
// Get Session value.
usr.CreatedBy = HttpContext.Session.GetString("CurrUSerID");
usr.LastLoggedDate = HttpContext.Session.GetString("logg"));
if (usr.CreatedBy != null)
{
ViewBag.Info = usr.CreatedBy;
ViewBag.Enfo = usr.LastLoggedDate;
return View();
}
else
{
return RedirectToAction("Login");
}
return View();
}
public IActionResult Login()
{
return View();
}
[HttpPost]
public IActionResult login(string userID, string password, DateTime LastLoggedDate)
{
UserDetail usr = new UserDetail();
// Get Session value.
// usr.CreatedBy = HttpContext.Session.SetString("CurrUSerID", usr.UserID);
if (!ModelState.IsValid)
{
return View();
}
UserDetail erp = objBL.GetLogin(userID, password);
if (erp != null)
{
HttpContext.Session.SetString("CurrUSerID", userID);
usr.UserID = userID;
var dt = LastLoggedDate.ToString("MM/dd/yyyy");
HttpContext.Session.SetString("Logg", dt);
usr.LastLoggedDate = LastLoggedDate;
return RedirectToAction("Create");
}
else
// Invalid UserId Or Password.
ViewBag.Error = "Login failed";
return View();
}
}
}
PLEASE HELP ME
namespace DLFeed100.Model
{
[Table("UserDetails")]
public class UserDetail
{
[Key]
public string UserID { get; set; }
public string Password { get; set; }
public string Name { get; set; }
public Int64 MobNumber { get; set; }
public string EmailID { get; set; }
public string EmpID { get; set; }
public string RoleID { get; set; }
public string DesignID { get; set; }
public DateTime? LastLoggedDate { get; set; }
public string CreatedBy { get; set; }
}
}