c# - Convert datetime in MVC4 view causes an error -


i have content entity model in project created ef6.

 public partial class content {     public content()     {         this.comments = new hashset<comment>();     }      public int id { get; set; }     public string subject { get; set; }     [datatype(datatype.multilinetext)]     public string brief { get; set; }     [uihint("tinymce_full"), allowhtml]     public string maintext { get; set; }     [datatype(datatype.datetime)]     public system.datetime dateofpublish { get; set; }     [datatype(datatype.imageurl)]     public string smallimageurl { get; set; }     [datatype(datatype.imageurl)]     public string bigimageurl { get; set; }     public string keywords { get; set; }     [datatype(datatype.datetime)]     public system.datetime dateofexpire { get; set; }     public string autherusername { get; set; }     public long visitvcount { get; set; }     public string visible { get; set; }     public int contentgroupid { get; set; }     public long likecount { get; set; }      public virtual contentgroup contentgroup { get; set; }     public virtual icollection<comment> comments { get; set; } } 

as can see have column dateofpublish , type of datetime .

i want convert date dateofpublish persian date function :

public string converttopersiantoshow(datetime? datetime)         {             string date;             datetime dt;              if (!datetime.hasvalue) return "";             dt = datetime.value;                       string year = convert.tostring(persian_date.getyear(dt));             string month = convert.tostring(persian_date.getmonth(dt));             string day = convert.tostring(persian_date.getdayofmonth(dt));             if (month.length == 1)             {                 month = "0" + convert.tostring(persian_date.getmonth(dt));             }             if (day.length == 1)             {                 day = "0" + convert.tostring(persian_date.getdayofmonth(dt));             }  convert.tostring(persian_date.getmonth(dt)) + "/" +              date = year + "/" + month + "/" + day;             return date;         } 

so call function in view (content view) tried show date in persian using function.so passed english date function can see here:

@{     viewbag.title = "index";     dateconverter objconverter = new dateconverter(); }          <td>             @html.displayfor(objconverter.converttopersiantoshow(modelitem => item.dateofpublish ))     </td> 

but got error:

argument type "lambda expression" not assignable parameter type 'system.nullable<system.datatime>' 

best regards

  @html.displayfor(modelitem => objconverter.converttopersiantoshow(item.dateofpublish )) 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -