I am making a small app and I need to show the DateTime, but I don’t know how.
I have a ViewModel:
public class ViewModel
{
public DateTime Time{ get; set; }
}
I have a controller called TimeController:
public ActionResult Index()
{
ViewModel v = new ViewModel();
v.Time = DateTime.Now;
return View(v);
}
And a View from Index:
ViewBag.Title = "Index";
}
<h2>Hello</h2>
Can somebody explain me how I can show the time on my view?
You can directly show it using @:
If your only purpose is to show DateTime, I wouldn’t bother using ViewModel or atleast wouldn’t store DateTime.Now just to be able to display it in View.