### Generate Bootstrap CSS Classes with Sitefinity Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt This C# code defines an interface for a provider that generates Bootstrap-compatible CSS classes for margins, paddings, and alignment. It also includes methods for retrieving configured button CSS classes. Usage examples demonstrate how to apply these classes within a widget model. ```csharp using Progress.Sitefinity.AspNetCore.Configuration; using Progress.Sitefinity.AspNetCore.Models.Common; using Progress.Sitefinity.AspNetCore.Widgets.Models.Common; namespace Progress.Sitefinity.AspNetCore.Widgets.ViewComponents.Common { public interface IStyleClassesProvider { StylingConfig StylingConfig { get; } OffsetSize DefaultMargin { get; } OffsetSize DefaultPadding { get; } // Generate margin classes (e.g., "mt-3 mb-4" for Bootstrap) string GetMarginsClasses(IHasMargins entity) where T : OffsetStyleBase; string GetMarginsClasses(OffsetStyleBase margins); // Generate padding classes (e.g., "pt-2 pb-3") string GetPaddingsClasses(IHasPaddings entity) where T : OffsetStyleBase; string GetPaddingsClasses(OffsetStyleBase paddings); // Generate alignment classes (e.g., "text-center justify-content-end") string GetAlignmenClasses(IHasPosition entity); // Get configured button CSS classes string GetConfiguredButtonClasses(string buttonType); string GetDefaultButtonClass(); } } // Usage in widget model public class ButtonModel : IButtonModel { private readonly IStyleClassesProvider styles; public ButtonModel(IStyleClassesProvider styles) { this.styles = styles; } public ButtonViewModel InitializeViewModel(ButtonEntity entity) { var viewModel = new ButtonViewModel(); // Apply styling through provider var margins = this.styles.GetMarginsClasses(entity); var alignment = this.styles.GetAlignmenClasses(entity); viewModel.CssClass = (entity.CssClass + " " + margins + " " + alignment).Trim(); viewModel.PrimaryButtonCssClass = this.styles.GetConfiguredButtonClasses("Primary"); viewModel.SecondaryButtonCssClass = this.styles.GetConfiguredButtonClasses("Secondary"); return viewModel; } } ``` -------------------------------- ### Pre-fetching Data for Content List Widgets in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt This C# code demonstrates a base preparation class for Sitefinity's ASP.NET Core widgets. It efficiently pre-fetches data for multiple ContentList widgets on a page before rendering, optimizing performance by handling pagination and resolving URL parameters. Dependencies include Sitefinity's ASP.NET Core SDK. ```csharp using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Progress.Sitefinity.AspNetCore.Models; using Progress.Sitefinity.AspNetCore.Preparations; using Progress.Sitefinity.AspNetCore.ViewComponents; using Progress.Sitefinity.AspNetCore.Web; using Progress.Sitefinity.AspNetCore.Widgets.Models.ContentList; using Progress.Sitefinity.RestSdk; namespace Progress.Sitefinity.AspNetCore.Widgets.Preparations { // Base preparation class internal abstract class ContentListBasePreparation : IRequestPreparation { internal const string PreparedData = nameof(ContentListBasePreparation.PreparedData); protected abstract string ContentListType { get; } private IContentListModelBase contentListModelBase; public ContentListBasePreparation(IContentListModelBase contentListModelBase) { this.contentListModelBase = contentListModelBase; } public Task Prepare(PageModel pageModel, IRestClient batchClient, HttpContext httpContext) { var context = httpContext.RequestServices.GetService(); // Find all ContentList widgets on the page var contentListWidgets = pageModel.AllViewComponentsFlat .Where(x => typeof(IViewComponentContext) .IsAssignableFrom(x.GetType()) && (x.Name == this.ContentListType)) .Select(context => context as IViewComponentContext) .ToList(); if (!contentListWidgets.Any()) return Task.CompletedTask; return this.PreparePager(pageModel, httpContext, contentListWidgets); } private Task PreparePager(PageModel pageModel, HttpContext httpContext, IList> components) { var tasks = new List(); var allTasksResolved = true; var resolvedSegments = new List(); foreach (var component in components) { // Pre-fetch content list data var task = this.contentListModelBase .HandleListView(component.Entity, pageModel.UrlParameters, httpContext) .ContinueWith((itemsTask) => { if (itemsTask.IsFaulted) { allTasksResolved = false; return; } var listViewModel = itemsTask.Result as ContentListCommonViewModel; if (listViewModel != null) { if (listViewModel.Pager != null) { var isPageNumberValid = listViewModel.Pager.IsPageNumberValid; if (isPageNumberValid) { // Store fetched data in component state component.State.Add(PreparedData, listViewModel); resolvedSegments.AddRange( listViewModel.Pager.ProcessedUrlSegments); } else { allTasksResolved = false; } } else { component.State.Add(PreparedData, listViewModel); } pageModel.MarkUrlParametersResolved( listViewModel.ResolvedUrlSegments); } }, TaskScheduler.Current); tasks.Add(task); } Task.WaitAll(tasks.ToArray()); resolvedSegments = resolvedSegments.Distinct().ToList(); if (pageModel.UrlParameters.Count != resolvedSegments.Count || !Enumerable.SequenceEqual( pageModel.UrlParameters.OrderBy(x => x), resolvedSegments.OrderBy(x => x))) { allTasksResolved = false; } if (allTasksResolved) { pageModel.MarkUrlParametersResolved(); } else { pageModel.MarkUrlParametersResolved(resolvedSegments); } return Task.WhenAll(tasks); } } // Concrete implementation ``` -------------------------------- ### Content List Preparation and View Component in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Demonstrates the preparation of content list data and its access within a Sitefinity widget's view component. It includes fallback logic for fetching data if not pre-prepared. This is crucial for dynamic content display in Sitefinity. ```csharp internal class ContentListPreparation : ContentListBasePreparation { public ContentListPreparation(IContentListModel contentListModel) : base(contentListModel) { } protected override string ContentListType => "SitefinityContentList"; } // Widget accesses prepared data from context.State public class ContentListViewComponent : ViewComponent { public async Task InvokeAsync( IViewComponentContext context) { // Check if data was pre-fetched if (context.State.ContainsKey(ContentListPreparation.PreparedData)) { var viewModel = context.State[ContentListPreparation.PreparedData] as ContentListViewModel; return this.View(viewModel); } // Fallback: fetch data now var viewModel = await this.model.HandleListView( context.Entity, context.UrlParameters, HttpContext); return this.View(viewModel); } } ``` -------------------------------- ### Sitefinity Button Widget ViewComponent in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt The entry point for the Sitefinity button widget, decorated with Sitefinity attributes. It initializes the widget's data model and returns a view model for rendering. Dependencies include Sitefinity's core view component libraries. ```csharp // 1. ViewComponent - Entry point decorated with Sitefinity attributes using Microsoft.AspNetCore.Mvc; using Progress.Sitefinity.AspNetCore.ViewComponents; using Progress.Sitefinity.AspNetCore.Widgets.Models.Button; namespace Progress.Sitefinity.AspNetCore.Widgets.ViewComponents { [SitefinityWidget(Title = "Call to action", EmptyIconText = "Create call to action", Order = 3, Section = WidgetSection.Basic, IconName = "call-to-action")] [ViewComponent(Name = "SitefinityButton")] public class ButtonViewComponent : ViewComponent { private IButtonModel model; public ButtonViewComponent(IButtonModel buttonModel) { this.model = buttonModel; } public virtual IViewComponentResult Invoke(IViewComponentContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); var viewModel = this.model.InitializeViewModel(context.Entity); return this.View(viewModel); } } } ``` -------------------------------- ### Fetch AI Assistants from External API in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt This C# code defines a client to fetch AI assistants from an external API. It uses HttpClient and Sitefinity's RestSdk to make the API call, retrieves necessary authentication and site information from the HttpContext and Sitefinity configuration, and handles potential exceptions. The fetched assistants are then prepared as ChoiceValueDtos for use in a designer UI. ```csharp using System; using System.Collections.Generic; using System.Net.Http; using System.Net.Http.Json; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Net.Http.Headers; using Progress.Sitefinity.AspNetCore.Configuration; using Progress.Sitefinity.AspNetCore.Widgets.Attributes; using Progress.Sitefinity.RestSdk; using Progress.Sitefinity.RestSdk.Dto; using Progress.Sitefinity.RestSdk.OData; using Progress.Sitefinity.Renderer.Designers.Dto; namespace Progress.Sitefinity.AspNetCore.Widgets.Models.SitefinityAssistant { internal class SitefinityAssistantClient : ISitefinityAssistantClient, IExternalChoicesProvider { private readonly IHttpContextAccessor httpAccessor; private readonly ILogger logger; private HttpClient AdministrationClient { get; set; } string IExternalChoicesProvider.Name => "SitefinityAssistantClient"; public SitefinityAssistantClient( IHttpClientFactory httpClientFactory, IConfiguration configuration, IHttpContextAccessor httpAccessor, ILogger logger) { this.AdministrationClient = httpClientFactory.CreateClient(); var config = new SitefinityAssistantConfig(); configuration.Bind(SitefinityAssistantConfig.SectionName, config); if (!string.IsNullOrEmpty(config.AssistantsAdminApiBaseUrl)) { this.AdministrationClient.BaseAddress = new Uri(config.AssistantsAdminApiBaseUrl); } this.httpAccessor = httpAccessor; this.logger = logger; } public async Task> GetAssistantsAsync() { List result = new List(); try { var httpContext = this.httpAccessor.HttpContext; var restClient = httpContext.RequestServices .GetRequiredService(); var args = new RequestArgs(); var requestCookie = httpContext.Request.Headers[HeaderNames.Cookie]; if (!string.IsNullOrEmpty(requestCookie)) { args.AdditionalHeaders.Add(HeaderNames.Cookie, requestCookie); } if (httpContext.Request.Query.TryGetValue("sf_site", out var siteId)) { args.AdditionalQueryParams.Add("sf_site", siteId); } var sitefinityConfig = httpContext.RequestServices .GetRequiredService(); if (!string.IsNullOrEmpty(sitefinityConfig.WebServiceApiKey)) { args.AdditionalHeaders.Add("X-SF-WebServiceApiKey", sitefinityConfig.WebServiceApiKey); } await restClient.Init(args); var response = await restClient .ExecuteUnboundFunction>>( new BoundFunctionArgs() { Name = "Default.GetAiAssistants" }); var assistants = response.Value; if (assistants?.Count > 0) { result.AddRange(assistants); } } catch (Exception ex) { this.logger.LogInformation( $"Error calling Sitefinity GetAiAssistants API: {ex.Message}"); } return result; } // Implements IExternalChoicesProvider for designer UI dropdown async Task> IExternalChoicesProvider.FetchChoicesAsync() { var choices = new List(); var assistants = await this.GetAssistantsAsync(); foreach (var assistant in assistants) { choices.Add(new ChoiceValueDto(assistant.Name, assistant.ApiKey)); } return choices; } public void Dispose() { this.AdministrationClient?.Dispose(); GC.SuppressFinalize(this); } } } // External provider interface namespace Progress.Sitefinity.AspNetCore.Widgets.Attributes { internal interface IExternalChoicesProvider { string Name { get; } Task> FetchChoicesAsync(); } } ``` -------------------------------- ### Fetch CMS Content with Sitefinity ASP.NET Core Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Demonstrates how to fetch and display CMS content using the ContentListModel in Sitefinity ASP.NET Core. This model handles content retrieval, selection expressions, and populating the view model for display. It utilizes Sitefinity's REST SDK for data access. ```csharp using System; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Progress.Sitefinity.AspNetCore.Web; using Progress.Sitefinity.AspNetCore.Widgets.ViewComponents.Common; using Progress.Sitefinity.RestSdk; using Progress.Sitefinity.RestSdk.Client; using Progress.Sitefinity.RestSdk.OData; namespace Progress.Sitefinity.AspNetCore.Widgets.Models.ContentList { public class ContentListModel : ContentListModelBase, IContentListModel { public ContentListModel(IODataRestClient restService, IRequestContext requestContext, IStyleClassesProvider styles) : base(restService, requestContext, styles) { } public override async Task HandleListView( ContentListEntityBase entity, ReadOnlyCollection urlParameters, HttpContext httpContext) { return await this.HandleListViewInternal(entity, urlParameters, httpContext); } private protected override void AddSelectExpression( ContentListEntityBase entity, GetAllArgs getAllArgs) { string selectExpression = (entity as ContentListEntity).SelectExpression; if (string.IsNullOrEmpty(selectExpression)) { getAllArgs.Fields.Add("*"); } else { var split = selectExpression.Split(';', StringSplitOptions.RemoveEmptyEntries); foreach (var field in split) { getAllArgs.Fields.Add(field.Trim()); } } } private protected override bool HideListView(ContentListEntityBase entityBase, string type) { var entity = entityBase as ContentListEntity; if (!string.IsNullOrEmpty(type) && !entity.ShowListViewOnChildDetailsView) { var detailItem = this.RequestContext.Model.DetailItem; if (detailItem != null) { var childTypes = (this.RestService as RestClient) .ServiceMetadata .GetChildTypes(type) .SelectMany(x => x); return childTypes.Any(x => x == detailItem.ItemType); } } return false; } private protected override ContentListViewModel PopulateViewModel( ContentListEntityBase entityBase) { var viewModel = new ContentListViewModel(); var entity = entityBase as ContentListEntity; viewModel.RenderLinks = !(entity.ContentViewDisplayMode == ContentViewDisplayMode.Master && entity.DetailPageMode == DetailPageSelectionMode.SamePage); viewModel.ListFieldMapping = entity.ListFieldMapping; viewModel.CssClasses = entity.CssClasses; viewModel.DetailItemUrl = new Uri( this.RequestContext.PageNode?.ViewUrl ?? string.Empty, UriKind.RelativeOrAbsolute); viewModel.Type = entityBase.SelectedItems?.Content?[0].Type; return viewModel; } } } ``` -------------------------------- ### Registering Sitefinity Widgets and Services in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt This code snippet shows how to register various Sitefinity widget models and related services (like request preparation and styling providers) into the ASP.NET Core dependency injection container. It's essential for making widgets available and functional within the application. ```csharp using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Progress.Sitefinity.AspNetCore.Configuration; using Progress.Sitefinity.AspNetCore.Preparations; using Progress.Sitefinity.AspNetCore.Widgets.ViewComponents.Common; using Progress.Sitefinity.Renderer.Designers; namespace Progress.Sitefinity.AspNetCore { public static class WidgetCollectionExtensions { // Register all general widgets public static void AddViewComponentModels(this IServiceCollection services) { // Widget models services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // Request preparation pipeline services.AddTransient(); services.AddTransient(); // Styling provider (singleton per request context) services.AddSingleton(serviceProvider => { var httpContextAccessor = serviceProvider.GetRequiredService(); var widgetConfig = serviceProvider.GetRequiredService(); return new StyleGenerator(widgetConfig, httpContextAccessor); }); // External data providers services.AddSingleton(); services.AddSingleton( provider => provider.GetRequiredService()); services.AddSingleton(); } } } namespace Progress.Sitefinity.AspNetCore.FormWidgets { public static class WidgetCollectionExtensions { // Register all form widgets public static void AddFormViewComponentModels(this IServiceCollection services) { services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddSingleton(); } } } // Usage in Startup.cs or Program.cs public class Startup { public void ConfigureServices(IServiceCollection services) { // Register Sitefinity services services.AddSitefinity(); // Register widget models services.AddViewComponentModels(); services.AddFormViewComponentModels(); // Register MVC with ViewComponents services.AddControllersWithViews(); } } ``` -------------------------------- ### Implement Sitefinity TextField Model in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Provides the logic for initializing and managing the text field's view model in Sitefinity forms. It inherits from a base class for common form functionalities and handles specific logic like input type mapping and validation message retrieval. Dependencies include Sitefinity's common models and style generators. ```csharp // 3. Model - Inherits from base class for common form logic using System; using System.Globalization; using System.Threading.Tasks; using Progress.Sitefinity.AspNetCore.FormWidgets.Entities.TextField; using Progress.Sitefinity.AspNetCore.FormWidgets.Models.Common; using Progress.Sitefinity.AspNetCore.FormWidgets.ViewModels.TextField; using Progress.Sitefinity.AspNetCore.FormWidgets.ViewComponents.Common; namespace Progress.Sitefinity.AspNetCore.FormWidgets.Models.TextField { public class TextFieldModel : TextModelBase, ITextFieldModel { public TextFieldModel(FormWidgetsStyleGenerator formWidgetsStyleGenerator) : base(formWidgetsStyleGenerator) { } public virtual Task InitializeViewModel(TextFieldEntity entity) { var model = this.InitializeViewModel(entity); var inputType = Enum.GetName(typeof(TextType), entity.InputType).ToLowerInvariant(); model.InputType = HandleInputType(inputType); return Task.FromResult(model); } protected override string GetRegularExpression(TextFieldEntity textEntity) { if (textEntity == null) throw new ArgumentNullException(nameof(textEntity)); return textEntity.RegularExpression; } protected override string GetRegularExpressionViolationMessage(TextFieldEntity textEntity) { if (textEntity == null) throw new ArgumentNullException(nameof(textEntity)); return textEntity.RegularExpressionViolationMessage; } private static string HandleInputType(string inputType) { if (inputType.ToUpperInvariant() == nameof(TextType.Phone).ToUpperInvariant()) return "tel"; return inputType; } } } ``` -------------------------------- ### Sitefinity Button Widget Entity Configuration in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Defines the configuration entity for the button widget, storing settings like button labels, links, and styles in the database. It utilizes Sitefinity's attributes for designer integration and data binding. Includes custom data types for link selection. ```csharp // 2. Entity - Configuration stored in database using System.Collections.Generic; using System.ComponentModel; using Progress.Sitefinity.AspNetCore.Models; using Progress.Sitefinity.Renderer.Designers; using Progress.Sitefinity.Renderer.Designers.Attributes; namespace Progress.Sitefinity.AspNetCore.Widgets.Models.Button { [SectionsOrder(PrimaryAction, SecondaryAction, Constants.ContentSectionTitles.DisplaySettings)] public class ButtonEntity : IHasMargins, IHasPosition { [DisplayName("Action label")] [ContentSection(PrimaryAction, 1)] [DescriptionExtended(InstructionalNotes = "Example: Learn more")] public string PrimaryActionLabel { get; set; } [DisplayName("Action link")] [ContentSection(PrimaryAction, 2)] [DataType(customDataType: "linkSelector")] public LinkModel PrimaryActionLink { get; set; } [DisplayName("Action label")] [ContentSection(SecondaryAction, 1)] public string SecondaryActionLabel { get; set; } [DisplayName("Action link")] [ContentSection(SecondaryAction, 2)] [DataType(customDataType: "linkSelector")] public LinkModel SecondaryActionLink { get; set; } [ContentSection(Constants.ContentSectionTitles.DisplaySettings)] [DefaultValue("{\"Primary\":{\"DisplayStyle\":\"Primary\"},\"Secondary\":{\"DisplayStyle\":\"Secondary\"}}")] public IDictionary Style { get; set; } [ContentSection(Constants.ContentSectionTitles.DisplaySettings, 1)] [DisplayName("Margins")] [TableView("CTA")] public MarginStyle Margins { get; set; } [Category(PropertyCategory.Advanced)] [DisplayName("CSS class")] public string CssClass { get; set; } private const string PrimaryAction = "Primary action"; private const string SecondaryAction = "Secondary action"; } } ``` -------------------------------- ### Sitefinity Button Widget Model Logic in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Implements the business logic for the button widget, transforming the stored entity data into a view model suitable for rendering. It handles CSS class generation for margins, alignment, and button styles. Depends on IStyleClassesProvider for style resolution. ```csharp // 3. Model - Business logic transforms Entity to ViewModel using System; using Progress.Sitefinity.AspNetCore.Widgets.ViewComponents.Common; namespace Progress.Sitefinity.AspNetCore.Widgets.Models.Button { public class ButtonModel : IButtonModel { private readonly IStyleClassesProvider styles; public ButtonModel(IStyleClassesProvider styles) { this.styles = styles; } public virtual ButtonViewModel InitializeViewModel(ButtonEntity entity) { if (entity == null) throw new ArgumentNullException(nameof(entity)); var viewModel = new ButtonViewModel(); viewModel.PrimaryActionLabel = entity.PrimaryActionLabel; viewModel.SecondaryActionLabel = entity.SecondaryActionLabel; viewModel.PrimaryActionLink = entity.PrimaryActionLink; viewModel.SecondaryActionLink = entity.SecondaryActionLink; var margins = this.styles.GetMarginsClasses(entity); var alignment = this.styles.GetAlignmenClasses(entity); viewModel.CssClass = (entity.CssClass + " " + margins + " " + alignment).Trim(); viewModel.PrimaryButtonCssClass = this.GetButtonCss("Primary", entity); viewModel.SecondaryButtonCssClass = this.GetButtonCss("Secondary", entity); viewModel.Attributes = entity.Attributes; return viewModel; } private string GetButtonCss(string buttonKey, ButtonEntity entity) { if (entity.Style != null && entity.Style.ContainsKey(buttonKey)) { var displayStyle = entity.Style[buttonKey].DisplayStyle; var resolvedStyle = this.styles.GetConfiguredButtonClasses(displayStyle); return !string.IsNullOrEmpty(resolvedStyle) ? resolvedStyle : displayStyle; } ``` -------------------------------- ### Create Sitefinity TextField ViewComponent in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Implements the ViewComponent for a text field in Sitefinity forms. It handles the asynchronous initialization of the view model and renders the form field. Dependencies include Microsoft.AspNetCore.Mvc and Sitefinity's form widget components. ```csharp // 1. ViewComponent - Async form widget using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Progress.Sitefinity.AspNetCore.FormWidgets.Entities.TextField; using Progress.Sitefinity.AspNetCore.FormWidgets.Models.TextField; using Progress.Sitefinity.AspNetCore.ViewComponents; using Progress.Sitefinity.Renderer.Forms; namespace Progress.Sitefinity.AspNetCore.FormWidgets.ViewComponents { [SitefinityFormWidget(FormFieldType.ShortText, Title = "Textbox", Order = 1, Section = WidgetSection.Basic, IconName = "textbox")] [ViewComponent(Name = "SitefinityTextField")] public class TextFieldViewComponent : ViewComponent { private ITextFieldModel model; public TextFieldViewComponent(ITextFieldModel textFieldModel) { this.model = textFieldModel; } public async Task InvokeAsync( IViewComponentContext context) { if (context == null) throw new ArgumentNullException(nameof(context)); var viewModel = await this.model.InitializeViewModel(context.Entity); return this.View(context.Entity.SfViewName, viewModel); } } } ``` -------------------------------- ### Button Widget Razor View Implementation (CSHTML) Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Implements the Button widget's UI using Razor syntax within an ASP.NET Core MVC application. It defines a helper method 'ButtonTag' to generate anchor tags for actions, conditionally rendering them based on labels and links. It utilizes Sitefinity's tag helpers (`sfdi-trigger`, `sfdi-predicate`, `Html.GenerateAnchorFromLink`, `Html.BuildAttributes`) for dynamic content and attribute generation. The view also applies CSS classes for styling and layout. ```cshtml @using Progress.Sitefinity.AspNetCore.TagHelpers @using Progress.Sitefinity.Renderer.Models @model Progress.Sitefinity.AspNetCore.Widgets.Models.Button.ButtonViewModel @{ string classAttr; void ButtonTag(string label, LinkModel linkModel, string cssClass, string typeToPlaceAttributeOn) { @if (!string.IsNullOrEmpty(label)) { classAttr = string.IsNullOrEmpty(cssClass) ? null : cssClass; @label } } classAttr = !string.IsNullOrEmpty(Model.CssClass) ? string.Format("d-flex align-items-center {0}", Model.CssClass) : "d-flex align-items-center"; }
@{ButtonTag(Model.PrimaryActionLabel, Model.PrimaryActionLink, string.Format(@"me-3 {0}", Model.PrimaryButtonCssClass), "Primary");} @{ButtonTag(Model.SecondaryActionLabel, Model.SecondaryActionLink, Model.SecondaryButtonCssClass, "Secondary");}
``` -------------------------------- ### Button ViewModel Definition (C#) Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Defines the data structure for a Button widget's presentation layer in an ASP.NET Core MVC application. It holds properties for labels, links, CSS classes, and custom attributes for primary and secondary actions. This ViewModel is used to pass data from the backend to the view for rendering. ```csharp using System.Collections.Generic using Progress.Sitefinity.AspNetCore.Models using Progress.Sitefinity.Renderer.Models namespace Progress.Sitefinity.AspNetCore.Widgets.Models.Button { public class ButtonViewModel { public string PrimaryActionLabel { get; set; } public LinkModel PrimaryActionLink { get; set; } public string SecondaryActionLabel { get; set; } public LinkModel SecondaryActionLink { get; set; } public string CssClass { get; set; } public string PrimaryButtonCssClass { get; set; } public string SecondaryButtonCssClass { get; set; } public IDictionary> Attributes { get; set; } } } ``` -------------------------------- ### Define Sitefinity TextField Entity in C# Source: https://context7.com/sitefinity/sitefinity-aspnetcore-mvc-widgets/llms.txt Defines the data structure and configuration for a text field entity in Sitefinity forms. It includes properties for input type, regular expression validation, and associated error messages. Dependencies include Sitefinity's common entity and designer attributes. ```csharp // 2. Entity - Form field configuration using System.ComponentModel; using Progress.Sitefinity.AspNetCore.FormWidgets.Entities.Common; using Progress.Sitefinity.Renderer.Contracts.Forms; using Progress.Sitefinity.Renderer.Designers; using Progress.Sitefinity.Renderer.Designers.Attributes; namespace Progress.Sitefinity.AspNetCore.FormWidgets.Entities.TextField { public class TextFieldEntity : TextEntityBase, ITextFieldContract { [ContentSection(Constants.ContentSectionTitles.LabelsAndContent, 3)] [DisplayName("Field type")] public TextType InputType { get; set; } [Category(PropertyCategory.Advanced)] [ContentSection("AdvancedMain", 3)] [DisplayName("Regular expression validation pattern")] public string RegularExpression { get; set; } [Category(PropertyCategory.Advanced)] [ContentSection("AdvancedMain", 4)] [DisplayName("Regular expression error message")] public string RegularExpressionViolationMessage { get; set; } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.