Skip to content

Add more mvc/view features API docs #26615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Mvc/Mvc.ViewFeatures/src/AntiforgeryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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;
Expand All @@ -10,6 +10,9 @@

namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
/// <summary>
/// Static class that adds extension methods to <see cref="IAntiforgery"/>. This class cannot be inherited.
/// </summary>
public static class AntiforgeryExtensions
{
/// <summary>
Expand Down
22 changes: 21 additions & 1 deletion src/Mvc/Mvc.ViewFeatures/src/CookieTempDataProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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;
Expand All @@ -18,6 +18,9 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// </summary>
public class CookieTempDataProvider : ITempDataProvider
{
/// <summary>
/// The name of the cookie.
/// </summary>
public static readonly string CookieName = ".AspNetCore.Mvc.CookieTempDataProvider";
private static readonly string Purpose = "Microsoft.AspNetCore.Mvc.CookieTempDataProviderToken.v1";

Expand All @@ -27,6 +30,13 @@ public class CookieTempDataProvider : ITempDataProvider
private readonly ChunkingCookieManager _chunkingCookieManager;
private readonly CookieTempDataProviderOptions _options;

/// <summary>
/// Initializes a new instance of <see cref="CookieTempDataProvider"/>.
/// </summary>
/// <param name="dataProtectionProvider">The <see cref="IDataProtectionProvider"/>.</param>
/// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
/// <param name="options">The <see cref="CookieTempDataProviderOptions"/>.</param>
/// <param name="tempDataSerializer">The <see cref="TempDataSerializer"/>.</param>
public CookieTempDataProvider(
IDataProtectionProvider dataProtectionProvider,
ILoggerFactory loggerFactory,
Expand All @@ -40,6 +50,11 @@ public CookieTempDataProvider(
_options = options.Value;
}

/// <summary>
/// Loads the temp data from the request.
/// </summary>
/// <param name="context">The <see cref="HttpContext"/>.</param>
/// <returns>The temp data.</returns>
public IDictionary<string, object> LoadTempData(HttpContext context)
{
if (context == null)
Expand Down Expand Up @@ -85,6 +100,11 @@ public IDictionary<string, object> LoadTempData(HttpContext context)
return new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// Save the temp data to the request.
/// </summary>
/// <param name="context">The <see cref="HttpContext"/>.</param>
/// <param name="values">The values.</param>
public void SaveTempData(HttpContext context, IDictionary<string, object> values)
{
if (context == null)
Expand Down
25 changes: 25 additions & 0 deletions src/Mvc/Mvc.ViewFeatures/src/DefaultHtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
/// <summary>
/// Default implementation of <see cref="IHtmlGenerator"/>.
/// </summary>
public class DefaultHtmlGenerator : IHtmlGenerator
{
private const string HiddenListItem = @"<li style=""display:none""></li>";
Expand Down Expand Up @@ -1208,6 +1211,21 @@ protected virtual TagBuilder GenerateFormCore(
return tagBuilder;
}

/// <summary>
/// Generate an input tag.
/// </summary>
/// <param name="viewContext">The <see cref="ViewContext"/>.</param>
/// <param name="inputType">The <see cref="InputType"/>.</param>
/// <param name="modelExplorer">The <see cref="ModelExplorer"/>.</param>
/// <param name="expression">The expression.</param>
/// <param name="value">The value.</param>
/// <param name="useViewData">Whether to use view data.</param>
/// <param name="isChecked">If the input is checked.</param>
/// <param name="setId">Whether this should set id.</param>
/// <param name="isExplicitValue">Whether this is an explicit value.</param>
/// <param name="format">The format.</param>
/// <param name="htmlAttributes">The html attributes.</param>
/// <returns></returns>
protected virtual TagBuilder GenerateInput(
ViewContext viewContext,
InputType inputType,
Expand Down Expand Up @@ -1356,6 +1374,13 @@ protected virtual TagBuilder GenerateInput(
return tagBuilder;
}

/// <summary>
/// Generate a link.
/// </summary>
/// <param name="linkText">The text for the link.</param>
/// <param name="url">The url for the link.</param>
/// <param name="htmlAttributes">The html attributes.</param>
/// <returns>The <see cref="TagBuilder"/>.</returns>
protected virtual TagBuilder GenerateLink(
string linkText,
string url,
Expand Down
28 changes: 27 additions & 1 deletion src/Mvc/Mvc.ViewFeatures/src/DefaultHtmlGeneratorExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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 Microsoft.AspNetCore.Mvc.Rendering;

namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
/// <summary>
/// Static class that adds extension methods to <see cref="IHtmlGenerator"/>. This class cannot be inherited.
/// </summary>
public static class DefaultHtmlGeneratorExtensions
{
/// <summary>
/// Generates a form.
/// </summary>
/// <param name="generator">The <see cref="IHtmlGenerator"/>.</param>
/// <param name="viewContext">The <see cref="ViewContext"/>.</param>
/// <param name="actionName">The action name.</param>
/// <param name="controllerName">The name of the controller.</param>
/// <param name="fragment">The fragment.</param>
/// <param name="routeValues">The route values.</param>
/// <param name="method">The form method.</param>
/// <param name="htmlAttributes">The html attributes.</param>
/// <returns></returns>
public static TagBuilder GenerateForm(
this IHtmlGenerator generator,
ViewContext viewContext,
Expand All @@ -28,6 +43,17 @@ public static TagBuilder GenerateForm(
return tagBuilder;
}

/// <summary>
/// Generates a form for a route.
/// </summary>
/// <param name="generator">The <see cref="IHtmlGenerator"/>.</param>
/// <param name="viewContext">The <see cref="ViewContext"/>.</param>
/// <param name="routeName">The nam eof the route.</param>
/// <param name="routeValues">The route values.</param>
/// <param name="fragment">The fragment.</param>
/// <param name="method">The form method.</param>
/// <param name="htmlAttributes">The html attributes.</param>
/// <returns>The <see cref="TagBuilder"/>.</returns>
public static TagBuilder GenerateRouteForm(
this IHtmlGenerator generator,
ViewContext viewContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,16 @@

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Static class that adds extension methods to <see cref="IMvcCoreBuilder"/>. This class cannot be inherited.
/// </summary>
public static class MvcViewFeaturesMvcCoreBuilderExtensions
{
/// <summary>
/// Add view related services.
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddViews(this IMvcCoreBuilder builder)
{
if (builder == null)
Expand Down Expand Up @@ -69,6 +77,12 @@ internal static void AddViewComponentApplicationPartsProviders(ApplicationPartMa
}
}

/// <summary>
/// Add view related services.
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
/// <param name="setupAction">The setup action for <see cref="MvcViewOptions"/>.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddViews(
this IMvcCoreBuilder builder,
Action<MvcViewOptions> setupAction)
Expand Down Expand Up @@ -119,6 +133,12 @@ public static IMvcCoreBuilder AddCookieTempDataProvider(
return builder;
}

/// <summary>
/// Configures <see cref="MvcViewOptions"/>.
/// </summary>
/// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
/// <param name="setupAction">The setup action.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder ConfigureViews(
this IMvcCoreBuilder builder,
Action<MvcViewOptions> setupAction)
Expand Down
Loading