Feedback messages utility for .NET Web application.
Display your feedbacks for web clients easily.
Messages that could not be rendered are persisted in the session until rendered.
0.6.0 (pre-release)
version >=.NETFramework 4.6.1, .NET Standard 2.0
FeedbackMessages.Example.WebForms
FeedbackMessages WebForms
FeedbackMessages.Mvc Mvc (.NETFramework)
FeedbackMessages.AspNetCore.Mvc Mvc, RazorPages
FeedbackMessages.AspNetCore.Blazor ServerSideBlazor
In your application's start up process.
FeedbackMessageSettings.CreateInitializer()
// custom renderer for feedback-message-panel
.SetMessageRendererFactory(() => {
var messageRenderer = new FeedbackMessageRenderer();
messageRenderer.OuterTagName = "div";
messageRenderer.InnerTagName = "span";
messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.INFO, "class", "ui info message");
messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.SUCCESS, "class", "ui success message");
messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.WARN, "class", "ui warning message");
messageRenderer.AppendOuterAttributeValue(FeedbackMessageLevel.ERROR, "class", "ui error message");
return messageRenderer;
})
// custom script builder.
.SetScriptBuilderInstance(new FeedbackMessageScriptBuilder(msg => $"alert('{msg.ToString()}');"))
// custom store serializer.
.SetStoreSerializerInstance(new FeedbackMessageStoreSerializer()
{
Deserializer = serial => /* TODO */ new FeedbackMessageStore(),
Serializer = store => /* TODO */ ""
})
// init configs
.Initialize();
-
FeedbackMessageRenderer renders ul and li tags that has "feedback-level" class attribute value.
-
FeedbackMessageScriptBuilder throws Exception.
-
FeedbackMessageStoreSerializer use System.Text.Json.JsonSerializer
Add FeedbackMessages dependency.
There is nothing you need to do to initialize. When start up application, add FeedbackMessages.FeedbackMessageHttpModule automatically.
Add messages.
// Control that inherits System.Web.UI.Control
using FeedbackMessages.Extensions;
...
this.InfoMessage("Information feedback message.");
this.SuccessMessage("Success feedback message.");
this.WarnMessage("Warning feedback message.");
this.ErrorMessage("Error feedback message.");
In the case of display messages as html element.
<!-- .aspx file -->
<%@ Register Assembly="FeedbackMessages" Namespace="FeedbackMessages.Components" TagPrefix="fm" %>
<!-- render message area -->
<fm:FeedbackMessagePanel runat="server" ID="FeedbackMessagePanel"></fm:FeedbackMessagePanel>
In the case of display messages using JavaScript.
// Control that inherits System.Web.UI.Control
using FeedbackMessages.Extensions;
this.AppendFeedbackMessageScript();
Add FeedbackMessages.Mvc dependency.
There is nothing you need to do to initialize. When start up application, add FeedbackMessages.FeedbackMessageHttpModule automatically.
Add messages.
// Controller that inherits System.Web.Mvc.Controller
using FeedbackMessages.Extensions;
・・・
this.InfoMessage("Information feedback message.");
this.SuccessMessage("Success feedback message.");
this.WarnMessage("Warning feedback message.");
this.ErrorMessage("Error feedback message.");
In the case of display messages as html element.
<!-- .cshtml file -->
@using FeedbackMessages.Extensions;
<!-- render message area -->
@Html.FeedbackMessagePanel()
In the case of display messages using JavaScript.
<!-- .cshtml file -->
@using FeedbackMessages.Extensions;
@Html.FeedbackMessageScript()
Ajax lazy load
public class YourController : Controller
{
public ActionResult AjaxFeedbackMessage()
{
var messageHtml = FeedbackMessageSettings.Instance.MessageRenderer.RenderMessages().ToString();
return new ContentResult()
{
ContentType = "text/html",
ContentEncoding = System.Text.Encoding.UTF8,
Content = messageHtml
};
}
}
<script>
$(function () {
$.ajax({
type: "POST", // GET
url: "/Your/AjaxFeedbackMessage",
success: function (messageHtml) {
if (!messageHtml) {
return;
}
$("#ajax-feedback-msg-container").html(messageHtml);
},
error: function (jqXHR, status, error) {
// TODO
}
});
});
</script>
<div id="ajax-feedback-msg-container"></div>
Add FeedbackMessages.AspNetCore.Mvc dependency.
Initialize FeedbackMessages in Startup.cs.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
// Required add filter
options.Filters.Add(FeedbackMessageActionFilter.Instance);
});
// Required add context accessor
services.AddHttpContextAccessor();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Required use middleware
app.UseFeedackMessages();
}
Add messages.
// Controller that inherits Microsoft.AspNetCore.Mvc.Controller
using FeedbackMessages.Extensions;
・・・
this.InfoMessage("Information feedback message.");
this.SuccessMessage("Success feedback message.");
this.WarnMessage("Warning feedback message.");
this.ErrorMessage("Error feedback message.");
In the case of display messages as html element.
<!-- .cshtml file -->
@using FeedbackMessages.Extensions;
<!-- render message area -->
@Html.FeedbackMessagePanel()
In the case of display messages using JavaScript.
<!-- .cshtml file -->
@using FeedbackMessages.Extensions;
<!-- render message area -->
@Html.FeedbackMessageScript()
Add FeedbackMessages.AspNetCore.Mvc dependency.
Initialize FeedbackMessages in Startup.cs.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
// Required add filter
options.Filters.Add(FeedbackMessageActionFilter.Instance);
});
// Required add context accessor
services.AddHttpContextAccessor();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Required use middleware
app.UseFeedackMessages();
}
Add messages.
// PageModel that inherits Microsoft.AspNetCore.Mvc.RazorPages.PageModel
using FeedbackMessages.Extensions;
・・・
this.InfoMessage("Information feedback message.");
this.SuccessMessage("Success feedback message.");
this.WarnMessage("Warning feedback message.");
this.ErrorMessage("Error feedback message.");
In the case of display messages as html element.
<!-- .cshtml file -->
@addTagHelper *, FeedbackMessages.AspNetCore.Mvc
<feedback-message-panel></feedback-message-panel>
In the case of display messages using JavaScript.
<!-- .cshtml file -->
@addTagHelper *, FeedbackMessages.AspNetCore.Mvc
<feedback-message-script></feedback-message-script>
Add FeedbackMessages.AspNetCore.Blazor dependency.
Initialize FeedbackMessages in Startup.cs.
public void ConfigureServices(IServiceCollection services)
{
// Required add context accessor
services.AddHttpContextAccessor();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// Required use middleware
app.UseFeedackMessages();
}
Add messages.
// Component that inherits Microsoft.AspNetCore.Components.ComponentBase
using FeedbackMessages.Extensions;
・・・
this.InfoMessage("Information feedback message.");
this.SuccessMessage("Success feedback message.");
this.WarnMessage("Warning feedback message.");
this.ErrorMessage("Error feedback message.");
<!-- .razor file -->
@using FeedbackMessages.Extensions;
@code {
this.InfoMessage("Information message.");
this.SuccessMessage("Success message.");
this.WarnMessage("Warning message.");
this.ErrorMessage("Error message.");
}
In the case of display messages as html element.
<!-- .razor file -->
@namespace FeedbackMessages.Components
<FeedbackMessagePanel @ref="feedbackMessagePanel"></FeedbackMessagePanel>
In the case of display messages using JavaScript.
<!-- .razor file -->
@namespace FeedbackMessages.Components
<FeedbackMessageScript @ref="feedbackMessageScript"></FeedbackMessageScript>
Refresh feedback message component.
To redraw, the component needs to be refreshed.
feedbackMessagePanel.RefreshRender();
//feedbackMessageScript.RefreshRender();