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" }));
        }
Example #2
0
 public NewsViewModel()
 {
     this.CreatedAt = PersianCalendarHelper.ConvertToPersian(DateTime.Now);
 }
Example #3
0
 DateTime? ITypeConverter <string, DateTime?> .Convert(ResolutionContext context)
 {
     return(PersianCalendarHelper.ConvertToGeorgian(context.SourceValue));
 }
Example #4
0
 public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     return(PersianCalendarHelper.ConvertToGeorgian(controllerContext.HttpContext.Request.Form[bindingContext.ModelName]));
 }
Example #5
0
 string ITypeConverter <DateTime?, string> .Convert(ResolutionContext context)
 {
     return(PersianCalendarHelper.ConvertToPersian(context.SourceValue));
 }