Configure project for NuGet packaging and implement WithData for chainable ViewData updates
This commit is contained in:
26
DigitalData.Core.API/ControllerExtensions.cs
Normal file
26
DigitalData.Core.API/ControllerExtensions.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace DigitalData.Core.API
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides extension methods for controllers in ASP.NET Core applications.
|
||||
/// This class is designed to enhance the functionality of <see cref="Controller"/>, <see cref="ControllerBase"/>,
|
||||
/// and their related results such as <see cref="ViewResult"/>.
|
||||
/// </summary>
|
||||
public static class ControllerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds or updates a value in the ViewData dictionary of a ViewResult. This method supports fluent chaining,
|
||||
/// enabling cleaner and more readable modifications to ViewData.
|
||||
/// </summary>
|
||||
/// <param name="viewResult">The ViewResult to which ViewData will be added or updated.</param>
|
||||
/// <param name="index">The key in the ViewData dictionary where the value will be stored.</param>
|
||||
/// <param name="value">The value to be stored in the ViewData dictionary.</param>
|
||||
/// <returns>The same ViewResult object with updated ViewData, allowing for additional chained operations.</returns>
|
||||
public static ViewResult WithData(this ViewResult viewResult, string index, object value)
|
||||
{
|
||||
viewResult.ViewData[index] = value;
|
||||
return viewResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user