希望这能让您入门。我在这里可能有几个错误,但应该很接近。我通常能够做到
@Html.Action("removeObjective", "CPDPlanSurface", new RouteValueDictionary{ {"planId", 123} })
或
@Html.ActionLink("Click Me!", "removeObjective", "CPDPlanSurface", new RouteValueDictionary{ {"planId", 123} })
我的 SurfaceController 通常如下所示:
using Umbraco.Web.Mvc;
public class CPDPlanSurfaceController : SurfaceController
{
[HttpGet]
public ActionResult removeObjective(int planId)
{
return RedirectToCurrentUmbracoPage();
}
}
表面控制器的路径最终类似于:
/umbraco/Surface/CPDPlanSurface/removeObjective?planId=123
我相信如果你想做自己的自定义路由,你需要做这样的事情:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
name: "CPDPlanRoutes",
url: "mypage/{action}/{planId}",
defaults: new { controller = "CPDPlanSurface", action = "Index", planId = UrlParameter.Optional });
}
}
然后在 ApplicationStarted 上:
public class StartUpHandlers : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
那么您应该可以像这样访问控制器上的方法:
@Url.Action("removeObjective", "CPDPlanSurface")