// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading.Tasks; using Microsoft.AspNet.Html; using Microsoft.AspNet.Mvc.ViewFeatures; namespace Microsoft.AspNet.Mvc.Rendering { /// /// PartialView-related extensions for . /// public static class HtmlHelperPartialExtensions { /// /// Returns HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// /// A that on completion returns a new instance containing /// the created HTML. /// public static Task PartialAsync( this IHtmlHelper htmlHelper, string partialViewName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null); } /// /// Returns HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A to pass into the partial view. /// /// A that on completion returns a new instance containing /// the created HTML. /// public static Task PartialAsync( this IHtmlHelper htmlHelper, string partialViewName, ViewDataDictionary viewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return htmlHelper.PartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData); } /// /// Returns HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A model to pass into the partial view. /// /// A that on completion returns a new instance containing /// the created HTML. /// public static Task PartialAsync( this IHtmlHelper htmlHelper, string partialViewName, object model) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return htmlHelper.PartialAsync(partialViewName, model, viewData: null); } /// /// Returns HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// /// Returns a new instance containing the created HTML. /// /// /// This method synchronously calls and blocks on /// /// public static IHtmlContent Partial( this IHtmlHelper htmlHelper, string partialViewName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData: null); } /// /// Returns HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A to pass into the partial view. /// /// Returns a new instance containing the created HTML. /// /// /// This method synchronously calls and blocks on /// /// public static IHtmlContent Partial( this IHtmlHelper htmlHelper, string partialViewName, ViewDataDictionary viewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return Partial(htmlHelper, partialViewName, htmlHelper.ViewData.Model, viewData); } /// /// Returns HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A model to pass into the partial view. /// /// Returns a new instance containing the created HTML. /// /// /// This method synchronously calls and blocks on /// /// public static IHtmlContent Partial( this IHtmlHelper htmlHelper, string partialViewName, object model) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return Partial(htmlHelper, partialViewName, model, viewData: null); } /// /// Returns HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A model to pass into the partial view. /// A to pass into the partial view. /// /// Returns a new instance containing the created HTML. /// /// /// This method synchronously calls and blocks on /// /// public static IHtmlContent Partial( this IHtmlHelper htmlHelper, string partialViewName, object model, ViewDataDictionary viewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } var result = htmlHelper.PartialAsync(partialViewName, model, viewData); return result.GetAwaiter().GetResult(); } /// /// Renders HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// /// In this context, "renders" means the method writes its output using . /// public static void RenderPartial( this IHtmlHelper htmlHelper, string partialViewName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } var result = htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null); result.GetAwaiter().GetResult(); } /// /// Renders HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A to pass into the partial view. /// /// In this context, "renders" means the method writes its output using . /// public static void RenderPartial( this IHtmlHelper htmlHelper, string partialViewName, ViewDataDictionary viewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } var result = htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData); result.GetAwaiter().GetResult(); } /// /// Renders HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A model to pass into the partial view. /// /// In this context, "renders" means the method writes its output using . /// public static void RenderPartial( this IHtmlHelper htmlHelper, string partialViewName, object model) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } var result = htmlHelper.RenderPartialAsync(partialViewName, model, viewData: null); result.GetAwaiter().GetResult(); } /// /// Renders HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A that renders the created HTML when it executes. /// /// In this context, "renders" means the method writes its output using . /// public static Task RenderPartialAsync( this IHtmlHelper htmlHelper, string partialViewName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData: null); } /// /// Renders HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A to pass into the partial view. /// A that renders the created HTML when it executes. /// /// In this context, "renders" means the method writes its output using . /// public static Task RenderPartialAsync( this IHtmlHelper htmlHelper, string partialViewName, ViewDataDictionary viewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return htmlHelper.RenderPartialAsync(partialViewName, htmlHelper.ViewData.Model, viewData); } /// /// Renders HTML markup for the specified partial view. /// /// The instance this method extends. /// /// The name of the partial view used to create the HTML markup. Must not be null. /// /// A model to pass into the partial view. /// A that renders the created HTML when it executes. /// /// In this context, "renders" means the method writes its output using . /// public static Task RenderPartialAsync( this IHtmlHelper htmlHelper, string partialViewName, object model) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (partialViewName == null) { throw new ArgumentNullException(nameof(partialViewName)); } return htmlHelper.RenderPartialAsync(partialViewName, model, viewData: null); } } }