Custom filtering of MVC Events widget
MVC events widget contains various predefined options to filter the list of displayed events. Although you can adjust almost every setting in the designer, you may want to extend the business logic behind some of these default filtering options. This tutorial will demonstrate how to extend a Eventswidget.
Perform the following:
- Create a new class that represents you new business logic for the Events widget.
Create aCustomEventModelclass that inherits from the defaultEventModel.
In this example, you additionally filter all events with title that contains Some Title text:C#using System; using Telerik.Sitefinity.Frontend.Events.Mvc.Models; namespace SitefinityWebApp { public class CustomEventModel : EventModel { protected override string CompileFilterExpression() { var filterExpression = base.CompileFilterExpression(); if (!filterExpression.IsNullOrEmpty()) filterExpression += " AND (Title.Contains(\"Some Title\"))"; else filterExpression = "(Title.Contains(\"Some Title\"))"; return filterExpression; } } } - Replace the original implementation of the Events widget model with the new model.
You do this using theBootstrapper.Bootstrappedevent.
Place the following code in yourGlobal.asaxfile:C#using System; using Telerik.Sitefinity.Abstractions; using Telerik.Sitefinity.Frontend; using Telerik.Sitefinity.Frontend.Events.Mvc.Models; namespace SitefinityWebApp { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender, EventArgs e) { Bootstrapper.Bootstrapped += this.Bootstrapper_Bootstrapped; } private void Bootstrapper_Bootstrapped(object sender, EventArgs e) { FrontendModule.Current.DependencyResolver.Rebind<IEventModel>().To<CustomEventModel>(); } } }
RESULT: You changed the default filtering of events due to the many virtual implementations of all controller methods and model methods.
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.