Various utility methods for the grid.
Exemplo n.º 1
0
        /// <summary>
        /// Generates the HTML for the Grid control based on the specified <paramref name="partial"/> view, or
        /// <paramref name="fallbackPartial"/> if <paramref name="partial"/> could not be found.
        /// </summary>
        /// <param name="helper">The <see cref="HtmlHelper"/> used for rendering the Grid control.</param>
        /// <param name="partial">The alias or virtual path to the partial view for rendering the Grid control.</param>
        /// <param name="fallbackPartial">The fallback partial view to be used if <paramref name="partial"/> isn't found.</param>
        /// <returns>An instance of <see cref="T:System.Web.HtmlString" />.</returns>
        public HtmlString GetHtmlOrFallback(HtmlHelper helper, string partial, string fallbackPartial)
        {
            // Some input validation
            if (helper == null)
            {
                throw new ArgumentNullException(nameof(helper));
            }
            if (String.IsNullOrWhiteSpace(partial))
            {
                throw new ArgumentNullException(nameof(partial));
            }

            // If the control isn't valid, we shouldn't render it
            if (!IsValid)
            {
                return(new HtmlString(""));
            }

            // Get a wrapper for the control
            GridControlWrapper wrapper = GridContext.Current.GetControlWrapper(this);

            // If the wrapper is NULL, we shouldn't render the control
            if (wrapper == null)
            {
                return(new HtmlString(""));
            }

            // Prepend the path to the "Editors" folder if not already specified
            if (GridUtils.IsValidPartialName(partial))
            {
                partial = "TypedGrid/Editors/" + partial;
            }

            // Prepend the path to the "Editors" folder if not already specified
            if (GridUtils.IsValidPartialName(fallbackPartial))
            {
                fallbackPartial = "TypedGrid/Editors/" + fallbackPartial;
            }

            // Render the partial view
            return(helper.ViewExists(partial) ? helper.Partial(partial, wrapper) : helper.Partial(fallbackPartial, wrapper));
        }
        /// <summary>
        /// Generates the HTML for the Grid row.
        /// </summary>
        /// <param name="helper">The <see cref="HtmlHelper"/> used for rendering the Grid row.</param>
        /// <param name="partial">The alias or virtual path to the partial view for rendering the Grid row.</param>
        /// <returns>Returns the Grid row as an instance of <see cref="HtmlString"/>.</returns>
        public HtmlString GetHtml(HtmlHelper helper, string partial)
        {
            // Some input validation
            if (helper == null)
            {
                throw new ArgumentNullException(nameof(helper));
            }
            if (String.IsNullOrWhiteSpace(partial))
            {
                throw new ArgumentNullException(nameof(partial));
            }

            // Prepend the path to the "Sections" folder if not already specified
            if (GridUtils.IsValidPartialName(partial))
            {
                partial = "TypedGrid/Sections/" + partial;
            }

            // Render the partial view
            return(helper.Partial(partial, this));
        }