### C# Alert Dialog Component Example for FineUI Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt This example demonstrates how to display an alert dialog using FineUI components within an ASP.NET Core Razor Page. It shows how to set the message, title, icon, and other properties of the alert, and how to trigger it, typically in response to a button click event. The AlertModel inherits from BaseModel for shared functionalities. ```csharp using Microsoft.AspNetCore.Mvc.RazorPages; public partial class AlertModel : BaseModel { protected void Page_Load(object sender, EventArgs e) { // Initialization code } protected void btnSubmit_Click(object sender, EventArgs e) { Alert alert = new Alert(); alert.Message = "Operation completed successfully!"; alert.Title = "Success"; alert.MessageBoxIcon = MessageBoxIcon.Success; alert.Target = Target.Top; alert.Width = 400; alert.MinWidth = 300; alert.MaxWidth = 600; alert.EnableClose = true; alert.Show(); } } ``` -------------------------------- ### C# Notification Component Examples for FineUI Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt This example showcases how to display temporary notification messages using the FineUI Notify component in an ASP.NET Core Razor Page. It illustrates simple notifications, notifications with custom icons, and fully customized notifications with control over message, icon, target, position, display duration, and header. The NotifyExampleModel inherits from BaseModel. ```csharp public partial class NotifyExampleModel : BaseModel { protected void btnShowNotify_Click(object sender, EventArgs e) { // Simple notification ShowNotify("Data saved successfully!"); // Notification with custom icon ShowNotify("Warning: Please review your input", MessageBoxIcon.Warning); // Custom notification with full control Notify notify = new Notify { Message = "Processing complete with 5 warnings", MessageBoxIcon = MessageBoxIcon.Information, Target = Target.Top, PositionX = Position.Center, PositionY = Position.Top, DisplayMilliseconds = 5000, ShowHeader = true, Title = "Process Results" }; notify.Show(); } } ``` -------------------------------- ### Configure FineUI Services and Middleware (C#) Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt This C# snippet details the configuration of services and the middleware pipeline in an ASP.NET Core application. It includes adding session state, antiforgery, FineUI services, and configuring Razor Pages with FineUI specific binders and filters. It also sets up localization and request localization options. ```csharp public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddDistributedMemoryCache(); services.AddSession(); services.AddAntiforgery(options => { options.Cookie.SecurePolicy = CookieSecurePolicy.SameAsRequest; }); services.Configure(x => { x.ValueCountLimit = 1024; x.ValueLengthLimit = 4194304; // 4MB per parameter }); // Add FineUI services services.AddFineUI(Configuration); // Configure Razor Pages with FineUI services.AddRazorPages().AddMvcOptions(options => { options.ModelBinderProviders.Insert(0, new FineUICore.JsonModelBinderProvider()); options.Filters.Insert(0, new FineUICore.RazorFormsFilter()); }).AddNewtonsoftJson().AddRazorRuntimeCompilation(); // Multi-language support services.AddLocalization(options => options.ResourcesPath = "Resources"); var supportedCultures = new List { new CultureInfo("zh-CN"), new CultureInfo("zh-TW"), new CultureInfo("en-US") }; services.Configure(options => { options.DefaultRequestCulture = new RequestCulture("zh-CN", "zh-CN"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; }); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseRequestLocalization(); app.UseStaticFiles(); app.UseSession(); app.UseRouting(); app.UseAuthorization(); // Use FineUI middleware (must be before UseEndpoints) app.UseFineUI(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } } ``` -------------------------------- ### Configure FineUI Application Settings (JSON) Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt This snippet shows the FineUI specific configurations within the appsettings.json file. It enables Razor Forms, sets the theme, debug mode, and various UI behavior options for components like grids and tabs. It also specifies excluded URLs and logging levels. ```json { "FineUI": { "EnableRazorForms": true, "DebugMode": true, "Theme": "Pure_Black", "EnableAnimation": true, "MobileAdaption": true, "JSLibrary": "All", "ExcludedURLs": [ "/Home/DownloadFile", "/Grid/Excel/ExportToExcel" ], "CustomScrollbar": true, "FormRedStarPosition": "BeforeText", "FormLabelAlign": "Right", "GridHeaderFilterIconVisible": true, "GridHeaderSortIconVisible": true, "GridPagingToolbarVisible": true, "GridPagerAlignRight": true, "GridShowSelectionMessage": true, "GridPagingType": "Arrow", "TabStripAnimationType": "Fade" }, "Logging": { "LogLevel": { "Default": "Error", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*" } ``` -------------------------------- ### Form Validation and Submission - C# Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt Demonstrates a basic form with input fields (textbox, dropdownlist, checkbox) and client-side validation for required fields. It handles form submission by displaying the entered data and provides a reset button to clear the fields. The `Page_Load` event initializes the dropdownlist. ```csharp public partial class FormBasicModel : BaseModel { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Initialize dropdownlist ddlDepartment.Items.Add(new ListItem("Engineering", "1")); ddlDepartment.Items.Add(new ListItem("Sales", "2")); ddlDepartment.Items.Add(new ListItem("Marketing", "3")); ddlDepartment.SelectedIndex = 0; } } protected void btnSubmit_Click(object sender, EventArgs e) { // Validate required fields if (string.IsNullOrEmpty(tbxName.Text)) { ShowNotify("Name is required!", MessageBoxIcon.Error); return; } // Process form data StringBuilder sb = new StringBuilder(); sb.Append("
    "); sb.AppendFormat("
  • Name: {0}
  • ", tbxName.Text); sb.AppendFormat("
  • Email: {0}
  • ", tbxEmail.Text); sb.AppendFormat("
  • Department: {0}
  • ", ddlDepartment.SelectedText); sb.AppendFormat("
  • Active: {0}
  • ", cbxActive.Checked); sb.Append("
"); ShowNotify("" + sb.ToString() + "", MessageBoxIcon.Success); } protected void btnReset_Click(object sender, EventArgs e) { // Clear form fields tbxName.Text = ""; tbxEmail.Text = ""; ddlDepartment.SelectedIndex = 0; cbxActive.Checked = false; ShowNotify("Form reset successfully!"); } } ``` -------------------------------- ### C# Base Page Model for FineUI Razor Forms Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt The BaseModel class provides essential utilities for FineUI pages, including multi-language resource support via IHtmlLocalizer, checking for postback requests, registering client-side scripts, displaying notifications, and retrieving event arguments from postbacks. It serves as a foundational class for other page models. ```csharp using Microsoft.AspNetCore.Mvc.RazorPages; public class BaseModel : PageModel { // Multi-language resource support private IHtmlLocalizer _localizer; public IHtmlLocalizer Localizer { get { if (_localizer == null) { _localizer = FineUICore.PageContext.GetLocalizer(this.GetType()); } return _localizer; } } // Shorthand for getting localized resources public string _R(string name, params object[] arguments) { if (arguments.Length == 0) { return Localizer.GetString(name); } return Localizer.GetString(name, arguments); } // Check if request is a postback public bool IsPostBack { get { return FineUICore.PageContext.IsFineUIAjaxPostBack(); } } // Register client-side scripts public void RegisterStartupScript(string scripts) { FineUICore.PageContext.RegisterStartupScript(scripts); } // Display notification message public virtual void ShowNotify(string message, MessageBoxIcon icon = MessageBoxIcon.Information) { Notify n = new Notify { Target = Target.Top, Message = message, MessageBoxIcon = icon, PositionX = Position.Center, PositionY = Position.Top, DisplayMilliseconds = 3000, ShowHeader = false }; n.Show(); } // Get event arguments from postback public string GetRequestEventArgument() { return Request.Form["__EVENTARGUMENT"]; } public string[] GetRequestEventArguments() { return GetRequestEventArgument().Split("$"); } } ``` -------------------------------- ### CheckboxList with Data Binding - C# Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt Creates a checkbox list populated from a server-side data source (`List`). It demonstrates data binding using `DataTextField` and `DataValueField`, pre-selecting items, and handling submission of selected values. It also includes an event handler for selection changes. ```csharp using System.Collections.Generic; public partial class CheckBoxListModel : BaseModel { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); } } private void LoadData() { List myList = new List { new TestClass("item1", "Option 1"), new TestClass("item2", "Option 2"), new TestClass("item3", "Option 3"), new TestClass("item4", "Option 4") }; CheckBoxList2.DataTextField = "Name"; CheckBoxList2.DataValueField = "Id"; CheckBoxList2.DataSource = myList; CheckBoxList2.DataBind(); // Pre-select items CheckBoxList2.SelectedValueArray = new string[] { "item1", "item3" }; } protected void btnSubmit_Click(object sender, EventArgs e) { // Get selected values string[] selectedValues = CheckBoxList2.SelectedValueArray; if (selectedValues.Length > 0) { string message = $"Selected items: {string.Join(", ", selectedValues)}"; ShowNotify(message); } else { ShowNotify("No items selected!"); } } protected void CheckBoxList_SelectedIndexChanged(object sender, EventArgs e) { // Handle selection change event ShowNotify($"Selection changed: {string.Join(", ", CheckBoxList2.SelectedValueArray)}"); } public class TestClass { public string Id { get; set; } public string Name { get; set; } public TestClass(string id, string name) { Id = id; Name = name; } } } ``` -------------------------------- ### Editable Grid Data Management with Session Storage (C#) Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt This C# code handles the logic for an editable grid, including data loading from session storage, processing user modifications (add, edit, delete), and saving changes back to session storage. It depends on Newtonsoft.Json for JSON processing and System.Data for DataTable operations. Input is typically data from the grid's modified rows, and output is the updated data source saved to the session. ```csharp using System.Data; using Newtonsoft.Json.Linq; public partial class GridEditorModel : BaseModel { private static readonly string KEY_SESSION = "GridEditor.GridEditor"; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); } } private void LoadData() { Grid1.DataSource = GetSourceData(); Grid1.DataBind(); } protected void btnSubmit_Click(object sender, EventArgs e) { DataTable source = GetSourceData(); // Process modified rows foreach (JObject modifiedRow in Grid1.ModifiedData) { string status = modifiedRow.Value("status"); int rowId = Convert.ToInt32(modifiedRow.Value("id")); if (status == "modified") { UpdateDataRow(modifiedRow, rowId, source); } else if (status == "newadded") { AddDataRow(modifiedRow, source); } else if (status == "deleted") { DeleteDataRow(rowId, source); } } // Save back to session HttpContext.Session.SetObject(KEY_SESSION, source); // Rebind grid Grid1.DataSource = source; Grid1.DataBind(); ShowNotify("Data saved successfully!"); } private void UpdateDataRow(JObject modifiedRow, int rowId, DataTable source) { Dictionary rowDict = modifiedRow.Value("values") .ToObject>(); DataRow rowData = FindRowByID(source, rowId); foreach (var kvp in rowDict) { if (source.Columns.Contains(kvp.Key)) { rowData[kvp.Key] = kvp.Value ?? DBNull.Value; } } } private void AddDataRow(JObject newRow, DataTable source) { DataRow row = source.NewRow(); Dictionary rowDict = newRow.Value("values") .ToObject>(); row["Id"] = source.Rows.Count + 1; foreach (var kvp in rowDict) { if (source.Columns.Contains(kvp.Key)) { row[kvp.Key] = kvp.Value ?? DBNull.Value; } } source.Rows.Add(row); } private void DeleteDataRow(int rowId, DataTable source) { DataRow row = FindRowByID(source, rowId); if (row != null) { source.Rows.Remove(row); } } private DataRow FindRowByID(DataTable table, int rowId) { foreach (DataRow row in table.Rows) { if (Convert.ToInt32(row["Id"]) == rowId) { return row; } } return null; } private DataTable GetSourceData() { if (HttpContext.Session.GetObject(KEY_SESSION) == null) { // Create initial data DataTable dt = new DataTable(); dt.Columns.Add("Id", typeof(int)); dt.Columns.Add("Name", typeof(string)); dt.Columns.Add("Gender", typeof(int)); dt.Columns.Add("Major", typeof(string)); dt.Columns.Add("EntranceYear", typeof(int)); dt.Rows.Add(1, "John Doe", 1, "Computer Science", 2020); dt.Rows.Add(2, "Jane Smith", 0, "Engineering", 2019); dt.Rows.Add(3, "Bob Wilson", 1, "Mathematics", 2021); HttpContext.Session.SetObject(KEY_SESSION, dt); } return HttpContext.Session.GetObject(KEY_SESSION); } } ``` -------------------------------- ### Session Helper for Object Storage in C# Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt Extends ISession to provide methods for storing and retrieving complex objects (like UserData) as JSON strings in session state. It relies on the Newtonsoft.Json library for serialization and deserialization. This helper simplifies managing complex data across requests. ```csharp using Microsoft.AspNetCore.Http; using Newtonsoft.Json; public static class SessionExtensions { public static void SetObject(this ISession session, string key, T value) { string json = JsonConvert.SerializeObject(value); session.SetString(key, json); } public static T GetObject(this ISession session, string key) { string json = session.GetString(key); if (string.IsNullOrEmpty(json)) { return default(T); } return JsonConvert.DeserializeObject(json); } } // Usage example public class UserSessionModel : BaseModel { private const string USER_DATA_KEY = "UserData"; public void SaveUserData(UserData data) { HttpContext.Session.SetObject(USER_DATA_KEY, data); ShowNotify("User data saved to session"); } public UserData GetUserData() { UserData data = HttpContext.Session.GetObject(USER_DATA_KEY); if (data == null) { data = new UserData { Name = "Guest", Role = "User" }; } return data; } protected void btnSaveSession_Click(object sender, EventArgs e) { var userData = new UserData { UserId = 123, Name = tbxName.Text, Email = tbxEmail.Text, Role = ddlRole.SelectedValue, LastLogin = DateTime.Now }; SaveUserData(userData); } protected void btnLoadSession_Click(object sender, EventArgs e) { UserData data = GetUserData(); tbxName.Text = data.Name; tbxEmail.Text = data.Email; ddlRole.SelectedValue = data.Role; ShowNotify($"Loaded data for {data.Name}"); } } public class UserData { public int UserId { get; set; } public string Name { get; set; } public string Email { get; set; } public string Role { get; set; } public DateTime LastLogin { get; set; } } ``` -------------------------------- ### Confirm Dialog with Custom Buttons - C# Source: https://context7.com/shixixiyue/fineuicore.examples.razorforms/llms.txt Displays a confirmation dialog with custom 'Delete' and 'Cancel' buttons. It uses client-side JavaScript for button actions and server-side C# for dialog configuration and event handling. The `Target.Top` property ensures the dialog appears in the top window. ```csharp public partial class ConfirmModel : BaseModel { protected void btnDelete_Click(object sender, EventArgs e) { Confirm confirm = new Confirm(); confirm.Title = "Confirm Delete"; confirm.Message = "Are you sure you want to delete this item?"; confirm.MessageBoxIcon = MessageBoxIcon.Question; confirm.Target = Target.Top; // Define custom buttons confirm.Buttons = new List { new ConfirmButton { Text = "Delete", OnClientClick = "handleDelete()" }, new ConfirmButton { Text = "Cancel", OnClientClick = "handleCancel()" } }; confirm.Show(); // Register client script to handle confirmation RegisterStartupScript(@" function handleDelete() { __doPostBack('btnConfirmedDelete', ''); } function handleCancel() { F.alert('Delete operation cancelled'); } "); } protected void btnConfirmedDelete_Click(object sender, EventArgs e) { // Perform actual deletion ShowNotify("Item deleted successfully!", MessageBoxIcon.Success); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.