How do populate date and time in asp.net mvc?
// controller
public class TimeLineDashboardController : Controller
{
// GET: TimeLineDashboard
public ActionResult Index()
{
// var userDt = DateTime.Now.ToString("MM/dd/yyyy hh:mm tt");
var nwDt = DateTime.Now.ToShortDateString();
ViewData["nowDt"] = nwDt;
return View();
}
}
// Model
public class Dashboard
{
// Map all values from the record list in TimeLine Application DB.
[Key]
[Display(Name = "Incident")]
public int Incident { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd HH:mm}")]
public DateTime dateTime { get; set; }
[Display(Name = "Resource")]
public string Resources { get; set; }
[Display(Name = "Description")]
public string Description { get; set; }
[Display(Name = "EndDate")]
public int EndDate { get; set; }
}
// Index
TimeLine
@ViewData["nowDt"] |
@ViewData["nowTm"] |
Sachin SinghPosted Sep 13, 2021, 1:36 PM