2015-09-01 44 views
0

我不知道,如果有人可以帮助我,请....MVC路由在一把umbraco实例

我在一个控制器(Controller称为CPDPlanSurfaceController)

public ActionResult removeObjective(int planId) 
    { 
     return RedirectToCurrentUmbracoPage(); 
    } 

和我创建了一个非常基本的ActionResult d喜欢创建一个映射到这个ActionResult的URL(显然这里会比这个重定向更多)。我不能使用@ Url.Action文本,因为这似乎不适用于Umbraco(网址总是空的)。另一个问题似乎是我的app_start文件夹中没有routeconfig.cs。所以我真的不知道从哪里开始。

最终,我想结束一个www.mysite.com/mypage/removeObjective/5的URL,但我不知道哪里可以开始创建这个'路线'。

任何人都可以让我五分钟指向正确的方向。

感谢, 克雷格

回答

3

希望这将让你开始。我可能在这里有几个错误,但它应该很接近。我通常能够做到

@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") 
+0

非常感谢matey。事实证明,我过度思考,你的建议指向了正确的方向。我结束了使用 '@ Html.ActionLink(“Delete Objective”,“removeObjective”,“CPDPlanSurface”,new {@planid = item.PlanID,@userName = Session [“username”],@redirectID = 3660}, null)' 很明显,我对控制器中的ActionResult做了一些更改(更多参数)。 干杯芽 – SxChoc