Create the controller
- In the
Mvc/Controllersfolder, create a new class that derives from theSystem.Web.Mvc.Controllerclass and name itCustomFormWidget. - Open the
CustomFormWidget.csfile and add the action to the controller. - Raise the event that invokes the event handler, subscribed to the custom event by adding it to the
CustomFormWidgetController.csfile.
Use the following code sample:
C#
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);
}
}
}