2

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

在我的 Umbraco (6) 视图之一中,我通过使用调用控制器方法

@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 语句并且它们确实有效,所以我确实理解为什么其中一些有效而另一些无效,但现在的主要问题是让我的国家/地区列表行动起作用。

4

2 回答 2

3

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

  1. 确保您的控制器正在扩展 Umbraco 的 SurfaceController
  2. 将其命名为 YourName*SurfaceController*
  3. 将 [PluginController("CLC")] 'annotation'(我来自 Java)添加到您的控制器。CLC 代表 CountryListController。你当然可以自己起名字。
  4. 将 PluginController 名称 (CLC) 作为“Area”参数添加到 Html.Action 调用中。

我的控制器:

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

       // Do stuff here to fill the CountryListingModel

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

我的部分观点(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"})
于 2013-11-17T23:01:37.877 回答
0

您可以使用 null 而不是使用 String.empty

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

如果您正在使用区域,则必须为每个区域覆盖 RegisterRoutes

public override string AreaName
    {
        get
        {
            return "CountryListing";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "CountryListing_default",
            "CountryListing/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }

我建议你看看同样的问题: https ://stackoverflow.com/a/11970111/2543986

于 2013-11-17T16:49:54.130 回答