asp.net-mvc - Html.Action() 结果为 "No route in the route table matches the supplied values"

标签 asp.net-mvc asp.net-mvc-routing umbraco6

这个问题已经讨论过很多次了,但我还没有找到适合我的具体情况的解决方案。

在我的 Umbraco (6) View 之一中,我使用调用 Controller 方法

@Html.Action("Index", "CountryListing");

这会导致“路由表中没有路由”异常。

我一直在摆弄 RegisterRoutes 方法,但没有成功。我想知道当我清空 RegisterRoutes 方法时,它是否仍然可以使用,因为该站点仍然可以运行。这就是现在的样子:

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }

我也尝试过在调用中添加一个空的“区域”,如下所示

@Html.Action("Index", "CountryListing", new {area: String.Empty});

我在其他地方使用 @Html.Action 语句,它们确实有效,所以我确实理解为什么其中一些有效而另一些无效,但现在的主要问题是让我的国家/地区列表操作发挥作用。

最佳答案

您可以通过执行以下操作来解决此问题

  1. 确保您的 Controller 扩展了 Umbraco 的 SurfaceController
  2. 将其命名为您的名字*SurfaceController*
  3. 将 [PluginController("CLC")]“注释”(我来自 Java)添加到您的 Controller 中。 CLC 代表国家列表 Controller 。当然,您可以自己起一个名字。
  4. 将 PluginController 名称 (CLC) 作为“Area”参数添加到 Html.Action 调用中。

我的 Controller :

[PluginController("CLC")]
public class CountryListingSurfaceController : SurfaceController
{
    public ActionResult Index()
    {
       var listing = new CountryListingModel();

       // Do stuff here to fill the CountryListingModel

       return PartialView("CountryListing", listing);
    }
}

我的部分 View (CountryListing.cshtml):

@inherits UmbracoViewPage<PatentVista.Models.CountryListingModel>

@foreach (var country in Model.Countries)
{
    <span>More razor code here</span>  
}

行动调用:

@Html.Action("Index", "CountryListingSurface", new {Area= "CLC"})

关于asp.net-mvc - Html.Action() 结果为 "No route in the route table matches the supplied values",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20032292/

相关文章:

ASP.NET Core 更改 AccessDenied 路由

ASP.NET MVC 2 urls/routes, View 如何与 Controller 相关?

ajax - Umbraco AJAX 调用不起作用

asp.net-mvc-4 - TempData 仅显示在子部分 View 中,而不显示在父部分 View 中

c# - 为什么我收到 "Value does not fall within the expected range"?

c# - 为什么我的复选框没有映射到 MVC 模型成员?

c# - 如何在自定义成员(member)资格提供商中实现 oAuth

asp.net-mvc - ASP.NET MVC 中的 Page.ResolveUrl 相当于什么?

c# - 没有 Controller 的路由和 url 中的操作

mysql - '/' 应用程序中的 umbraco 站点服务器错误