I just started learning ASP.Net MVC, I'm trying to change my previous code (which was based on WebForm) to MVC but I encounter an Issue, Imagine I'm working on article to show a list of it:
Here is the Model:
public class Article
{
public int ID { get; set; }
public string ArticleTitle { get; set; }
public DateTime CreationDateTime { get; set; }
}
Here is part of View:
<span> @Html.DisplayFor(modelItem => item.CreationDateTime )</span>
I wrote a method in controller to change Geregrian date to Persian date:
public string ConvertToPersianDate(object date)
{
clsWorkWithDate wwd = new clsWorkWithDate();
date = wwd.gregorianToShamsi(Convert.ToDateTime(date));
return date.ToString();
}
Now I want to get access this function in view, something like this:
@ConvertToPersianDate(@Html.DisplayFor(modelItem => item.CreationDateTime ))
But the error message says that ConvertToPersianDate
does not exist in the current context, it seems it's not accessible in view.
I had no problem when it was in WebForm list view:
<%# ConvertToPersianDate(Eval("CreationDateTime")) %>
How can I resolve the matter?