【问题标题】:Is there an equivalent of Java's Spring MVC style url mapping for C#/.NET?是否有等效于 C#/.NET 的 Java 的 Spring MVC 样式 url 映射?
【发布时间】:2011-08-13 20:49:19
【问题描述】:

我正在寻找 Spring MVC's url mapping using annotations 的 C# 等价物,即我可以用 Java 编写:

@Controller
@RequestMapping("/some-friendly-url/")
class MyController
{
    @RequestMapping(value = "/{type}/more-seo-stuff/{color}", method = RequestMethod.GET)
    public List<SomeDTO> get(@PathVariable String type,
                             @PathVariable String color,
                             int perPage) {
        ...
    }

    @RequestMapping(method = RequestMethod.POST)
    public String post(@RequestBody SomeDTO somethingNew) {
        ...
    }
}

它实际上比这个简单的例子更强大,任何熟悉这个概念的人都知道。

我试图搜索如何使用 ASP.MVC 3 或 MonoRail 实现相同的目标,这两个框架似乎都基于 RoR 的约定优于配置“//”理念,而且很难实现上面有它们,并且需要控制器类之外的大量定制路由条目,只有一小部分功能可通过属性获得。 Spring.NET 似乎也没有解决这个问题,因为 ASP.MVC 的路由功能已经足够了。

在 C# 世界中是否有任何东西可以提供这种类型的功能?我正要开始考虑写一些自己的东西来解决这个问题,但我希望不必这样做。

编辑: 终于在 NuGet 上找到了“AttributeRouting”项目:https://github.com/mccalltd/AttributeRouting/wiki/1.-Getting-Started。完美运行。不支持 Spring MVC 提供的全部功能,但支持其中的大部分。

Akos Lukacs 还指出了 ITCloud 下面的另一个不错的库。然而,不幸的是,NuGet 上没有。

【问题讨论】:

标签: c# .net asp.net-mvc spring-mvc castle-monorail


【解决方案1】:

当然,你可以使用 Spring.NET:

http://www.springframework.net/

【讨论】:

  • 我查看了 Spring.NET 并在那里找不到答案。你能为我指出正确的方向吗?即使用 Spring.NET 的上述代码的等价物是什么?
【解决方案2】:

我最终使用了https://github.com/mccalltd/AttributeRouting/wiki/1.-Getting-Started。为了保持问题的完整性,现在才发布。

【讨论】:

    猜你喜欢
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    • 2017-01-18
    • 2023-03-08
    相关资源
    最近更新 更多