【问题标题】:Routing values to the MVC Player function?将值路由到 MVC Player 函数?
【发布时间】:2014-10-08 09:31:09
【问题描述】:

在 Composite C1 应用程序中,我试图将值从 URL 传递给 MVC Player 函数,但我遇到了麻烦,因为这些值是路径的一部分,而不是查询字符串中的一部分。

网址如下所示:

/AuctionDetailsGallery/3624734/Test-Versteigerung-2

AuctionDetailsGallery 是一个包含 MvcPlayer 功能的复合 C1 页面。 3624734 是(动态)ID,“Test-Versteigerung-2”是一个用户友好的名称

然后应该调用 MvcPlayer

/AuctionViewer/FilterGalleryPositions

(“AuctionViewer”是控制器,“FilterGalleryPositions”是动作。)

ID 必须传递给操作,但使用不同的名称(“SelectedAuctions”)。

所以本质上,如果用户调用

/AuctionDetailsGallery/3624734/Test-Versteigerung-2

我想渲染 MVC 动作

/AuctionViewer/FilterGalleryPositions?SelectedAuctions=3624734

我该怎么做?

我将 MvcPlayer 路径设置为 "/AuctionViewer/FilterGalleryPositions" 并玩弄了路由,但我总是收到消息

找不到路径“/3624734/Test-Versteigerung-2”的控制器 或者不实现 IController。

这是因为 Render 函数会检查 PathInfo 并将我设置的 Path 替换为 PathInfo(如果可用)。我想如果附加 PathInfo 会更有用,但我不确定如何使用当前的 MVC Player 实现路由我的值。

【问题讨论】:

  • @GeorgeStocker Erm,我不确定你为什么要进行编辑。我很确定这不是错误,这是 C1 MvcPlayer 的工作方式。我只是不知道如何让我的场景使用该功能。
  • 对此感到抱歉,我想在您的 other 帖子中介绍 Composite C1。虽然拥有源代码在这里也有帮助。

标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing c1-cms


【解决方案1】:

如果我正确理解您的问题,我相信您是在询问路线。

使用属性路由只需在控制器操作上声明路由(假设控制器名称为 AuctionViewerController):

[Route("AuctionDetailsGallery/{selectedAuctions}/Test-Versteigerung-2")]
public ActionResult FilterGalleryPositions(int selectedAuctions)
{
...
}

使用路由表,您可以定义如下内容:

routes.MapRoute(
   name: "AuctionDetails",
   url: "AuctionDetailsGallery/{selectedAuctions}/Test-Versteigerung-2",
   defaults: new { controller = "AuctionViewer", action = "FilterGalleryPositions" }
);

【讨论】:

  • 我知道路线。问题是我无法直接路由到操作。 (按照您的建议)操作和视图嵌入在复合页面中。因此,请求被路由到 Composite C1 页面,该页面包含一个 MvcPlayer 函数以及相应的操作路径。然后我必须以某种方式将请求 URL 中的值获取到 MvcPlayer 操作中的操作。
  • 明确一点:这是一个复合 C1 CMS 问题。我怀疑这可以在没有 C1 知识的情况下通过 vanilla MVC 方法解决。我已经在他们的论坛上问过了,但没有得到回应。
猜你喜欢
  • 2019-03-29
  • 2012-07-21
  • 2011-05-05
  • 2015-07-12
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
  • 1970-01-01
  • 2021-05-16
相关资源
最近更新 更多