Create the controller

  1. In the Mvc/Controllers folder, create a new class that derives from the System.Web.Mvc.Controller class and name it CustomFormWidget.
  2. Open the CustomFormWidget.cs file and add the action to the controller.
  3. Raise the event that invokes the event handler, subscribed to the custom event by adding it to the CustomFormWidgetController.cs file.

Use the following code sample:

 
using System.Web.Mvc;
using Telerik.Sitefinity.Mvc;
using Telerik.Sitefinity.Services;
using SitefinityWebApp.Mvc.Models;
using SitefinityWebApp.Events;
namespace SitefinityWebApp.Mvc.Controllers
{
[ControllerToolboxItem(Name = "CustomFormWidget", Title = "CustomFormWidget", SectionName = "MvcWidgets")]
public class CustomFormWidgetControllerEvents : Controller
{
public ActionResult Index()
{
return View("Default");
}
public ActionResult Submit(CustomFormWidgetModel model)
{
if (!ModelState.IsValid)
{
return View();
}
//Raise the event
EventHub.Raise(new CustomSubmitFormEvent
{
Email = model.Email,
FirstMeal = model.FirstMeal,
SecondMeal = model.SecondMeal,
Dessert = model.Dessert,
});
return View(model);
}
}
}

Was this article helpful?