我花了数小时试图让自定义树显示在umbraco的自定义部分。 - 没有成功。自定义部分和自定义树MVC方法
到目前为止,我已经设法创建了一个新的部分,但是当我单击该部分时没有任何反应。
应该发生的事情是自定义树应该与一个节点一起显示。当你点击该节点时,它应该显示一个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 Class中放置了断点,但没有一个被击中。
我还在Application Started上放置了断点,并且这些断点正在被击中,所以我非常肯定路线配置正确。
有什么,我失踪?我已经看到其他使用树形控制器TreeController的例子,这让我困惑了一下。
任何想法? - 非常卡住
YES !!!!!这正是我挣扎着的!我也花了数小时试图找出造成这个错误的原因! – Nicke
:-) - 很高兴我能帮助! –