Create the controller
To create a new controller, perform the following:
- In the context menu of folder
Mvc\Controllers, click Add» Class... - Name the class
FeatureController.cs. - Inherit from the
System.Web.Mvc.Controllerclass. - Add method
Indexthat returns an object of typeActionResult.
Each controller can have multiple actions, which are mapped to methods in the class. - Modify the code of the
Indexaction to return a list of features in version 5.1.
In this example, theIndexaction returns a list of items from the model that you created in the previous article.
Use the following code sample:
C#
using SitefinityWebApp.Mvc.Models;
using System.Collections.Generic;
using System.ComponentModel;
using System.Web.Mvc;
using Telerik.Sitefinity.Mvc;
namespace SitefinityWebApp.Mvc.Controllers
{
public class FeatureController : Controller
{
public ActionResult Index()
{
var listOfFeatures = new List<Feature>();
listOfFeatures.Add(new Feature() { Name = "Pure MVC mode", Version = 5.1 });
listOfFeatures.Add(new Feature() { Name = "Classic MVC mode", Version = 5.1 });
listOfFeatures.Add(new Feature() { Name = "Hybrid MVC mode", Version = 5.1 });
return View(listOfFeatures);
}
}
}
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.