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 async Task InvokeAsync(HttpContext httpContext)
        {
            var path = httpContext.Request.Path.ToString();

            if (path.StartsWith(PathPrefixProvider.Prefix, StringComparison.InvariantCultureIgnoreCase))
            {
                ModeProvider.SetIsPageEditing(httpContext, true);

                httpContext.Request.Path = "/" + path.Substring(PathPrefixProvider.Prefix.Length);
            }

            await Next(httpContext);
        }
        public static IHtmlContent AddPageEditing(this IHtmlHelper html)
        {
            if (ModeProvider == null)
            {
                ModeProvider = (IModeProvider)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IModeProvider));
            }

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

            if (AddPageEditingHtmlGenerator == null)
            {
                AddPageEditingHtmlGenerator = (IAddPageEditingHtmlGenerator)html.ViewContext.HttpContext.RequestServices.GetService(typeof(IAddPageEditingHtmlGenerator));
            }

            return(new HtmlString(AddPageEditingHtmlGenerator.GenerateHtml()));
        }