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