我花了數小時試圖讓自定義樹顯示在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
:-) - 很高興我能幫助! –