UoN.AspNetCore.FeedbackMessage 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package UoN.AspNetCore.FeedbackMessage --version 1.1.0                
NuGet\Install-Package UoN.AspNetCore.FeedbackMessage -Version 1.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UoN.AspNetCore.FeedbackMessage" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UoN.AspNetCore.FeedbackMessage --version 1.1.0                
#r "nuget: UoN.AspNetCore.FeedbackMessage, 1.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UoN.AspNetCore.FeedbackMessage as a Cake Addin
#addin nuget:?package=UoN.AspNetCore.FeedbackMessage&version=1.1.0

// Install UoN.AspNetCore.FeedbackMessage as a Cake Tool
#tool nuget:?package=UoN.AspNetCore.FeedbackMessage&version=1.1.0                

UoN.AspNetCore.FeedbackMessage

License Build Status

What is it?

Reusable bits for ASP.NET Core to make displaying feedback messages after action redirects easy.

What are its features?

It provides the following:

  • An enum of Bootstrap 4 based Alert Types
  • A model class representing a Feedback Message
  • Extension methods for setting and getting FeedbackMessageModels at TempData["FeedbackMessage"]
  • A TagHelper for rendering any Feedback Message at TempData["FeedbackMessage"]
  • A Controller for returning a partial view (constructed by the TagHelper); useful for requesting via AJAX to add to a page.
  • An extension method for adding the controller (and partial view) to MVC.

Dependencies

The library targets netstandard2.0 and depends upon ASP.Net Core 2.0 MVC.

If you can use ASP.Net Core 2 MVC, you can use this library.

Usage

Acquiring the library

NuGet

This library is available from nuget.org

Build from source

We recommend building with the dotnet cli, but since the package targets netstandard2.0 and depends only on ASP.Net Core 2.0 MVC, you should be able to build it in any tooling that supports those requirements.

  • Have the .NET Core SDK 2.0 or newer
  • dotnet build
  • Optionally dotnet pack
  • Reference the resulting assembly, or NuGet package.

Standard Server-side usage

  1. Acquire the library via one of the methods above.
  2. Use this.SetFeedbackMessage() inside an MVC Controller method.
  3. Import TagHelpers from this assembly
    • add the following to a Razor View, or to _ViewImports.cshtml:
    • @addTagHelper *, UoN.AspNetCore.FeedbackMessage
  4. Use the <uon-feedbackmessage /> TagHelper in a a Razor View.
  5. ????
  6. PROFIT!
An example:

MyController.cs

public class MyController : Controller
{
    ...

    public IActionResult MyAction()
    {
        this.SetFeedbackMessage("Hello!", AlertTypes.Info);
        return View();
    }
}

MyAction.cshtml

<div>
    <uon-feedbackmessage />

    The rest of my HTML content is here and very interesting.
</div>
  • If a Feedback Message is not set, <uon-feedbackmessage /> will simply collapse into nothing.
  • If a Feedback Message is set, <uon-feedbackmessage /> will turn into something like the following:
<div class="alert alert-info">
    Hello!
</div>

AJAX usage

  1. Acquire the library via one of the methods above.
  2. Use services.AddMvc().AddAjaxFeedbackMessageSupport() inside Startup.ConfigureServices()
  3. Optionally specify an MVC Route template for the FeedbackMessageAjaxController, else it will default to /FeedbackMessageAjax as per MVC default conventions
  4. Write some javascript that makes an AJAX request, and puts the result onto the page.
  5. ????
  6. PROFIT!
An example:

Startup.cs

public void ConfigureServices(IServiceCollection services)
        {
            ...

            services.AddMvc()
                .AddAjaxFeedbackMessageSupport(services);

            ...
        }

feedback-message.js

//global function that assumes we have jquery...
window.feedbackMessage = (message, type) => {
    let feedback = $("#feedback-message"); //this is a div on the page

    $.get({
        url: "/FeedbackMessageAjax",
        data: { "message": message, "type": type },
        success: function(content) {
            //use animation to make it clear the message has changed if there was already one there!
            feedback.fadeOut(200, "swing", function() {
                feedback.html(content);

                feedback.fadeIn(100);
            });
        }
    });
};

...

//some situation in which we want a feedback message
window.feedbackMessage("Hello!", "info");

Contributing

Contributions are welcome.

If there are issues open, please feel free to make pull requests for them, and they will be reviewed.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 1,004 1/11/2019
2.0.0 828 11/29/2018
1.1.0 1,214 11/3/2017
1.0.0 1,049 10/24/2017

This release features AJAX support:

- A Controller and Partial View that can be used to get feedback message html via ajax
- An `IMvcBuilder` extension for registering the aforementioned controller from this assembly.