UoN.AspNetCore.FeedbackMessage
1.1.0
See the version list below for details.
Install-Package UoN.AspNetCore.FeedbackMessage -Version 1.1.0
dotnet add package UoN.AspNetCore.FeedbackMessage --version 1.1.0
<PackageReference Include="UoN.AspNetCore.FeedbackMessage" Version="1.1.0" />
paket add UoN.AspNetCore.FeedbackMessage --version 1.1.0
#r "nuget: UoN.AspNetCore.FeedbackMessage, 1.1.0"
// 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
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
FeedbackMessageModel
s atTempData["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
- Acquire the library via one of the methods above.
- Use
this.SetFeedbackMessage()
inside an MVC Controller method. - Import TagHelpers from this assembly
- add the following to a Razor View, or to
_ViewImports.cshtml
: @addTagHelper *, UoN.AspNetCore.FeedbackMessage
- add the following to a Razor View, or to
- Use the
<uon-feedbackmessage />
TagHelper in a a Razor View. - ????
- 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
- Acquire the library via one of the methods above.
- Use
services.AddMvc().AddAjaxFeedbackMessageSupport()
insideStartup.ConfigureServices()
- Optionally specify an MVC Route template for the
FeedbackMessageAjaxController
, else it will default to/FeedbackMessageAjax
as per MVC default conventions - Write some javascript that makes an AJAX request, and puts the result onto the page.
- ????
- 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 | Versions |
---|---|
.NET | net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows |
.NET Core | netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 |
.NET Standard | netstandard2.0 netstandard2.1 |
.NET Framework | net461 net462 net463 net47 net471 net472 net48 |
MonoAndroid | monoandroid |
MonoMac | monomac |
MonoTouch | monotouch |
Tizen | tizen40 tizen60 |
Xamarin.iOS | xamarinios |
Xamarin.Mac | xamarinmac |
Xamarin.TVOS | xamarintvos |
Xamarin.WatchOS | xamarinwatchos |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc (>= 2.0.0)
- Microsoft.Extensions.FileProviders.Embedded (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
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.