public static MvcHtmlString Editor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression) { ModelMetadata metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); string propname = html.ViewData.Model.Item(expression); string incomingValue = null; var httpCookie = html.ViewContext.RequestContext.HttpContext.Request.Cookies["lang"]; if (metadata.Model is DateTime && (httpCookie.IsNull() || httpCookie.Value == Cultures.Persian)) { incomingValue = PersianCalendarHelper.ConvertToPersian(((DateTime)metadata.Model).ToShortDateString()); } if (string.IsNullOrEmpty(incomingValue)) { return(html.TextBox(propname, null, new { @class = "datepicker TextField" })); } return(html.TextBox(propname, incomingValue, new { @class = "datepicker TextField" })); }
public NewsViewModel() { this.CreatedAt = PersianCalendarHelper.ConvertToPersian(DateTime.Now); }
DateTime? ITypeConverter <string, DateTime?> .Convert(ResolutionContext context) { return(PersianCalendarHelper.ConvertToGeorgian(context.SourceValue)); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { return(PersianCalendarHelper.ConvertToGeorgian(controllerContext.HttpContext.Request.Form[bindingContext.ModelName])); }
string ITypeConverter <DateTime?, string> .Convert(ResolutionContext context) { return(PersianCalendarHelper.ConvertToPersian(context.SourceValue)); }