Manager Views

Last Updated: 2019-04-26

This article shows a basic example of how to add a custom view to the manager interface. To add a menu item in the manager to navigate to the view, please refer to Manager Menu.

Controller

To make the controller a part of the manager interface make sure you add it to the Manager area. If you want to use the built in functions for notifying users with error, information or success messages you can derive your controller from the class MessageControllerBase.  This base class gives you access to the following methods:

void SuccessMessage(string msg, bool persist = true)
void ErrorMessage(string msg, bool persist = true)
void InformationMessage(string msg, bool persist = true)
Below is an example of a basic controller with actions for listing, editing and deleting entities.

using Microsoft.AspNetCore.Mvc;
using Piranha.Areas.Manager.Controllers;

namespace MyNamespace.Controllers
{
[Area("Manager")]
[Route("manager")]
public MyFunctionController : MessageControllerBase
{
[Route("myfunction")]
public IActionResult List()
{
return View(...);
}

[Route("myfunction/add")]
public IActionResult Add()
{
return View("Edit", ...);
}

[Route("myfunction/edit/{id}")]
public IActionResult Edit(...)
{
return View(...);
}

[Route("myfunction/delete/{id}")]
public IActionResult Delete(...)
{
// Delete the specified entitiy
...

// Notify the user
SuccessMessage("The entity was deleted!");

// Redirect to the list view
return RedirectToView("List");
}
}
}

View

The view should be positioned following the standard mvc area structure in order to be found. For example, the view for the above List action should be positioned at ~/Areas/Manager/Views/MyFunction/List.cshtml.

The example view below adds a basic button for adding a new entity, and shows the current message if present. It also shows a table with the current items, an edit link and a delete button.

@model ...
@{
ViewBag.Title = "My Function";
ViewBag.Controller = "MyFunction";
}

<div class="row">
<div class="col-sm-12 buttons">
<a href="@Url.Action("Add")" class="btn btn-labeled btn-primary pull-right">
<span class="btn-label">
<i class="fas fa-plus"></i>
</span>Add
</a>
</div>
</div>

@if (!string.IsNullOrWhiteSpace(ViewBag.Message))
{
<div class="row">
<div class="col-sm-12">
<div class="@ViewBag.MessageCss">
@Html.Raw(ViewBag.Message)
</div>
</div>
</div>
}

<table class="table table-striped table-main">
<thead>
<tr>
<th>Title</th>
<th class="actions one"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Items)
{
<tr>
<td class="text-limit-cell">
<span class="text-limit">
<a href="@Url.Action("Edit", new { id = item })">@item.Title</a>
</span>
</td>
<td class="actions one">
<a class="remove" href="@Url.Action("Delete", new {id = role.Id})">
<span class="fas fa-trash text-danger"></span>
</a>
</td>
</tr>
}
</tbody>
</table>