希望這將讓你開始。我可能在這裏有幾個錯誤,但它應該很接近。我通常能夠做到
@Html.Action("removeObjective", "CPDPlanSurface", new RouteValueDictionary{ {"planId", 123} })
OR
@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
I相信如果你想要做自己的自定義路由,你需要做這樣的事情:
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")
非常感謝matey。事實證明,我過度思考,你的建議指向了正確的方向。我結束了使用 '@ Html.ActionLink(「Delete Objective」,「removeObjective」,「CPDPlanSurface」,new {@planid = item.PlanID,@userName = Session [「username」],@redirectID = 3660}, null)' 很明顯,我對控制器中的ActionResult做了一些更改(更多參數)。 乾杯芽 – SxChoc