【发布时间】:2017-08-01 14:40:15
【问题描述】:
我花了好几个小时试图让自定义树显示在 umbraco 的自定义部分中。 - 没有成功。
到目前为止,我已经设法创建了一个新部分,但是当我单击该部分时,没有任何反应。
应该发生的是应该用一个节点显示自定义树。当您单击该节点时,它应该显示一个 MVC 视图。
这是我到目前为止所做的,它基于本教程。
A.创建部分
{
[Application("rewards", "Rewards", "icon-gift", 15)]
public class RewardsSection: IApplication
{
}
}
B.创建树
[Tree("rewards", "rewardsTree", "Rewards")]
[PluginController("Rewards")]
public class RewardsTree : BaseTree
{
public RewardsTree(string application)
: base(application)
{ }
protected override void CreateRootNode(ref XmlTreeNode rootNode)
{
rootNode.NodeType = "rewards";
rootNode.NodeID = "-1";
rootNode.Menu = new List<IAction> { ActionRefresh.Instance };
}
public override void Render(ref XmlTree tree)
{
var IndexNode = XmlTreeNode.Create(this);
IndexNode.NodeID = "0";
IndexNode.NodeType = "Home";
IndexNode.Text = "Home";
IndexNode.Action = "javascript:openPage('/umbraco/backoffice/Plugins/Rewards/Index');";
IndexNode.Icon = "icon-home";
IndexNode.HasChildren = false;
IndexNode.Menu = new List<IAction>();
OnBeforeNodeRender(ref tree, ref IndexNode, EventArgs.Empty);
if (IndexNode != null)
{
tree.Add(IndexNode);
OnAfterNodeRender(ref tree, ref IndexNode, EventArgs.Empty);
}
}
public override void RenderJS(ref StringBuilder Javascript)
{
var js = $"function openPage(url){{UmbClientMgr.contentFrame(url);}}";
Javascript.Append(js);
}
protected override void CreateAllowedActions(ref List<IAction> actions)
{
actions.Clear();
actions.Add(ActionNew.Instance);
actions.Add(ActionDelete.Instance);
actions.Add(ContextMenuSeperator.Instance);
actions.Add(ActionRefresh.Instance);
}
}
C. RegisterRoutes(在 ApplicationStarted 上调用)
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "umbraco/backoffice/Plugins/{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
public class StartUpHandlers : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
D.后端控制器 - 返回我想查看的视图。
public class RewardsController : UmbracoAuthorizedController
{
public ActionResult Index()
{
return View("~/App_Plugins/Rewards/Views/RewardsHome/Index.cshtml");
}
}
那么我错过了什么?
我在 RewardsTree 类中设置了断点,但没有一个被击中。
我还在 Application Started 上设置了断点,并且这些断点被击中,所以我很确定路由配置正确。
我有什么遗漏的吗?我看过其他使用 TreeBase 的 TreeController 的示例,这让我有点困惑。
有什么想法吗? - 非常卡住
【问题讨论】:
标签: asp.net-mvc model-view-controller umbraco umbraco7