I have a MVC action method which accept 2 date parameters. I tried to use .ToString
but it gives me this error:
Returns the text representation of the value of the current Nullable object.
No overload for method 'ToString' takes 1 arguments.
I need to convert it to yyyy-MM-dd
before pass it to the view. Otherwise, the textbox won't able to show the date value. Here is the code
public ActionResult Index(DateTime? dateFrom, DateTime? dateTo)
{
ViewBag.DateFrom = dateFrom.ToString("yyyy-MM-dd");
return View();
}