So recently, I came up with a way to dynamically build a nav-bar menu where the Controller (And its Index ActionMethod) would be listed in a horizontal bar at the top of each page (via Site.Master) but also based on the user's assigned roles. Each Controller listed would also list (in a vertical drop-down) the ActionMethods available to the user.
See here for the code I wrote to create an Extended Controller class for ASP.NET MVC which solved the above mentioned problem.
I realized that I also want to automatically create a default Index page for each Controller that lists all the ActionMethods available and a short 1 or 2 sentence description of each ActionMethod, but was pondering how to attach the description to the ActionMethod.
My assumption is that I need to do 3 things:
(1) Create my own Attribute, say, Description and decorate each ActionMethod in each Controller like so:
[Authorize(Roles="Admin")]
public class SomeController : ExtController
{
[Description("This method adjusts all of your widgets making them better.")]
public ActionResult TweakWidgets()
{
return View();
}
}
(2) Create a public ActionResult Index() method in my base class (ExtController) which will be used by every class inheriting ExtController to show a listing of the ActionMethods and their Descriptions available to that user.
(3) Create an Index.aspx View in Views/Shared that will build such a page.
Is this a sensible approach? Is there a better way to do this?