Skip to content

Instantly share code, notes, and snippets.

@Matthew-Wise
Last active November 8, 2021 17:38
Show Gist options
  • Save Matthew-Wise/dfa75dfb5607bbea156422ebd70f1308 to your computer and use it in GitHub Desktop.
Save Matthew-Wise/dfa75dfb5607bbea156422ebd70f1308 to your computer and use it in GitHub Desktop.
Umbraco v9 RenderMvcController replacement options
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ViewEngines;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Web;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Cms.Web.Common.PublishedModels;
public class HomePageController : RenderController
{
public HomePageController(ILogger<RenderController> logger, ICompositeViewEngine compositeViewEngine, IUmbracoContextAccessor umbracoContextAccessor)
: base(logger, compositeViewEngine, umbracoContextAccessor)
{
}
/// <summary>
/// Overrides RenderControllers default action.
/// The Current content is accessible via CurrentPage as IPublishContent
/// </summary>
/// <returns></returns>
public override IActionResult Index()
{
return CurrentTemplate(CurrentPage);
}
/// <summary>
/// This action is used when the template name matches the method name.
/// /// The Current content is accessible via CurrentPage as IPublishContent
/// </summary>
/// <returns></returns>
public IActionResult HomePage2()
{
return CurrentTemplate(CurrentPage);
}
/// <summary>
/// This action is used when the template name matches the method name.
/// </summary>
/// <param name="model">Provides access to the current content using model.Content as IPublishContent</param>
/// <returns></returns>
public IActionResult HomePage3(ContentModel model)
{
return CurrentTemplate(model);
}
/// <summary>
/// This action is used when the template name matches the method name.
/// </summary>
/// <param name="model">Provides access to the current content using model.Content as the strongly typed model Homepage</param>
/// <returns></returns>
public IActionResult HomePage(ContentModel<Homepage> model)
{
return CurrentTemplate(model);
}
/// <summary>
/// This action is used when the template name matches the method name.
/// </summary>
/// <param name="model">Provides access to the current content as the strongly typed model Homepage</param>
/// <returns></returns>
public IActionResult HomePage(Homepage model) //credit to https://github.com/bakersbakebread for finding this one.
{
return CurrentTemplate(model);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment