コード例 #1
0
        public static IHtmlContent PropertyFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression)
        {
            if (ModeProvider == null)
            {
                ModeProvider = (IModeProvider)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IModeProvider));
            }

            var result = html.DisplayFor(expression);

            if (ModeProvider.GetIsPageEditing(html.ViewContext.HttpContext) != true)
            {
                return(result);
            }

            if (PropertyForHtmlGenerator == null)
            {
                PropertyForHtmlGenerator = (IPropertyForHtmlGenerator)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IPropertyForHtmlGenerator));
            }

            string resultString;

            using (var writer = new StringWriter())
            {
                result.WriteTo(writer, HtmlEncoder.Default);
                resultString = writer.ToString();
            }

            return(new HtmlString(PropertyForHtmlGenerator.GenerateHtml(html.ViewData.Model, expression, resultString)));
        }
コード例 #2
0
        public static MvcHtmlString PropertyFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
        {
            if(ModeProvider == null)
            {
                ModeProvider = DependencyResolver.Current.GetService<IModeProvider>();
            }

            var result = html.DisplayFor(expression);

            if(ModeProvider.GetIsPageEditing(html.ViewContext.HttpContext) != true)
            {
                return result;
            }

            if (PropertyForHtmlGenerator == null)
            {
                PropertyForHtmlGenerator = DependencyResolver.Current.GetService<IPropertyForHtmlGenerator>();
            }

            return new MvcHtmlString(PropertyForHtmlGenerator.GenerateHtml(html.ViewData.Model, expression, result.ToString()));
        }