<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core.Models;
using System.Web.Mvc;
using Umbraco.Web.Templates;
using System.IO;
using System.Web.Routing;
using Umbraco.Web.Mvc;

namespace Umbraco.Web
{
    public static class GridTemplateExtensions
    {
        public static MvcHtmlString GetGridHtml(this IPublishedProperty property, string framework = "bootstrap3")
        {
            var view = "Grid/" + framework;
            return new MvcHtmlString(RenderPartialViewToString(view, property.Value));
        }

        public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem)
        {
            return GetGridHtml(contentItem, "bodyText", "bootstrap3");
        }

        public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias)
        {
            return GetGridHtml(contentItem, propertyAlias, "bootstrap3");    
        }

        public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias, string framework)
        {
            var view = "Grid/" + framework;
            var model = contentItem.GetProperty(propertyAlias).Value;

            return new MvcHtmlString(RenderPartialViewToString(view, model));
        }

        private static string RenderPartialViewToString(string viewName, object model)
        {
            using (var sw = new StringWriter())
            {<commit_msg>Fixes: U4-6111 GetGridHtml throws an exception if no grid value is available<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Umbraco.Core.Models;
using System.Web.Mvc;
using Umbraco.Web.Templates;
using System.IO;
using System.Web.Routing;
using Umbraco.Web.Mvc;

namespace Umbraco.Web
{
    [Obsolete("This should not be used, GetGridHtml extensions on HtmlHelper should be used instead")]
    public static class GridTemplateExtensions
    {
        public static MvcHtmlString GetGridHtml(this IPublishedProperty property, string framework = "bootstrap3")
        {
            var view = "Grid/" + framework;
            return new MvcHtmlString(RenderPartialViewToString(view, property.Value));
        }

        public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem)
        {
            return GetGridHtml(contentItem, "bodyText", "bootstrap3");
        }

        public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias)
        {
            Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");

            return GetGridHtml(contentItem, propertyAlias, "bootstrap3");    
        }

        public static MvcHtmlString GetGridHtml(this IPublishedContent contentItem, string propertyAlias, string framework)
        {
            Mandate.ParameterNotNullOrEmpty(propertyAlias, "propertyAlias");

            var view = "Grid/" + framework;
            var prop = contentItem.GetProperty(propertyAlias);
            if (prop == null) throw new NullReferenceException("No property type found with alias " + propertyAlias);
            var model = prop.Value;

            var asString = model as string;
            if (asString.IsNullOrWhiteSpace()) return new MvcHtmlString(string.Empty);

            return new MvcHtmlString(RenderPartialViewToString(view, model));
        }

        private static string RenderPartialViewToString(string viewName, object model)
        {

            using (var sw = new StringWriter())
            {
{'fraction_non_alphanumeric': 0.07633168588687535, 'fraction_numerical': 0.0030203185063152112, 'mean_word_length': 3.0254143646408838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1447090', 'n_tokens_mistral': 930, 'n_tokens_neox': 920, 'n_words': 255}