I am trying to get current time with DateTime.Now.ToString() and to assign as a value to Model.DatePosted, using Razor in my View.The problem is always when i try to add value to DatePosted I get NullReferenceException. I think I dont have problem with my code, but the error still remains. How can I fix that?
Here is the definition of DatePosted variable in my model table:
[Display(Name = "Date")]
public string DatePosted { get; set; }
Here is the code in my View:
@model BicycleWorldShop.Models.Review
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
string currentDate= DateTime.Now.ToString();
Model.DatePosted = currentDate;
}