.Net的RestfulRouting更改默认值';id';param
相当基本的问题,但我似乎在文档中找不到它。我一直在(通过nuget)将其集成到MVC4应用程序中,但在某些情况下,最好调整参数,或者更改名称,或者在控制器操作中包含多个参数 e、 g 或.Net的RestfulRouting更改默认值';id';param,.net,asp.net-mvc,.net,Asp.net Mvc,相当基本的问题,但我似乎在文档中找不到它。我一直在(通过nuget)将其集成到MVC4应用程序中,但在某些情况下,最好调整参数,或者更改名称,或者在控制器操作中包含多个参数 e、 g 或 是否有一个示例或文档涵盖此场景?如果我理解正确,您正试图使用RestfulRouting 我不确定是否100%可行,但您可以尝试创建自定义路线: 另外还提供了两种方法,以便在需要时向管线集添加自定义管线。Map是一种可链接的方法,允许您添加标准映射。Route是一种允许您将自定义管线添加到管线集的方法 例如 如
是否有一个示例或文档涵盖此场景?如果我理解正确,您正试图使用RestfulRouting 我不确定是否100%可行,但您可以尝试创建自定义路线: 另外还提供了两种方法,以便在需要时向管线集添加自定义管线。Map是一种可链接的方法,允许您添加标准映射。Route是一种允许您将自定义管线添加到管线集的方法 例如 如何使用它?
公共类路由:路由集
{
公共覆盖无效映射(映射器映射)
{
Root(x=>x.Show());
将.Path(“test/{id}”)映射到(x=>x.test()).constraint(“id”,@“\d+”);
map.Resource();
资源(博客=>
{
blogs.As(“weblogs”);
blogs.Only(“索引”、“显示”);
blogs.Collection(x=>{
x、 获取(“最新”);
x、 发布(“某些行为”);
);
blogs.Member(x=>x.Put(“移动”);
blogs.Resources(posts=>
{
除“创建”、“更新”、“销毁”外;
员额.资源(c=>c,但“销毁”除外);
});
});
}
}
公共类MVC应用程序:System.Web.HttpApplication
{
受保护的无效应用程序\u Start()
{
ViewEngines.Engines.Clear();
添加(新的RestfulRoutingViewEngine());
RouteTable.Routes.MapRoutes();
}
}
如何使用:
这里可以找到完整的指南:我阅读了一些文档,可能会给出一些关于如何选择不同命名的提示,但看到您选择的框架如何将路由合并在一起,我相信可能不可能有多个参数……遗憾的是,现在没有时间深入研究RestfulRouting来解决这个问题。你试过AttributeRouting吗?AttributeRouting.net你能澄清一下
Map(字符串url)
方法在什么地方使用吗?在我的routeset类中,我覆盖Map(Imapper Map)
,目前所有的映射资源都在其中。我真的没有机会使用RestfulRouting库来实现。但我从Rails知道它,所以应该更类似。我添加了一个更好的代码示例,其中包含您所说的覆盖。
/resource/:id/:slug
public ActionResult Show(int id, string slug) { return View(); }
/resource/:custom_param_name
public ActionResult Show(string custom_param_name) { return View(); }
Map("posts/{year}/{slug}")
.To<PostsController>(x => x.Post(-1, ""))
.Constrain("slug", @"\w+")
.Constrain("year", @"\d+");
Route(new Route("posts/{action}",
new RouteValueDictionary(new { controller = "posts" }),
new MvcRouteHandler());
Map("resource/{custom_param}")
.To<ResourcesController>(x => x.Resource(-1, ""))
.Constrain("custom_param", @"\w+");
Route(new Route("resource/custom",
new RouteValueDictionary(new { controller = "resource" }),
new MvcRouteHandler());
public ActionResult Custom(string custom_param) { return View(); }
public class Routes : RouteSet
{
public override void Map(Mapper map)
{
map.Root<HomeController>(x => x.Show());
map.Path("test/{id}").To<TestController>(x => x.Test()).Constrain("id", @"\d+");
map.Resource<SessionsController>();
map.Resources<BlogsController>(blogs =>
{
blogs.As("weblogs");
blogs.Only("index", "show");
blogs.Collection(x => {
x.Get("latest");
x.Post("someaction");
);
blogs.Member(x => x.Put("move"));
blogs.Resources<PostsController>(posts =>
{
posts.Except("create", "update", "destroy");
posts.Resources<CommentsController>(c => c.Except("destroy"));
});
});
}
}
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RestfulRoutingViewEngine());
RouteTable.Routes.MapRoutes<Routes>();
}
}