Is it possible to check TempData internally if the condition is in Asp.Net MVC?

I want to check TempDatainside the conditions if. But I get an error message.

My controller

public ActionResult Customer(PurchaseViewModel purchaseviewmodel)
{
    TempData["Fromdt"] = purchaseviewmodel.FromDate;
    TempData["todt"] = purchaseviewmodel.ToDate;
    If(TempData["Fromdt"] == Convert.ToDateTime("01/01/0001")&& TempData["todt"] == Convert.ToDateTime("01/01/0001"))
    {
        //...
    }
    else
    {
        //...
    }
    return View(Customer);
}

Why am I getting model values ​​in Tempdata, I want to pass the values ​​that I get in TempDate for another action. Therefore, I use only TempData. Now I get the error. Error

The == operator is not applied between the object and System.DateTime.

I tried my level to explain the problem. Therefore, it helps me to solve this problem. And I need TempData not to store the values ​​directly in the variable. I can save the value in a variable like

    var  fmdt = purchaseviewmodel.FromDate;
    var  todt = purchaseviewmodel. ToDate;

TempData , TempData .

+5
1

Temp object, == DateTime .

, TempData, .

datetime. DateTime.MinValue

if((Datetime)TempData["FromDate"] == DateTime.MinValue)
+5

Source: https://habr.com/ru/post/1665402/


All Articles