这个问题已经讨论过很多次了,但我还没有找到适合我的具体情况的解决方案。
在我的 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 语句,它们确实有效,所以我确实理解为什么其中一些有效而另一些无效,但现在的主要问题是让我的国家/地区列表操作发挥作用。
最佳答案
您可以通过执行以下操作来解决此问题
- 确保您的 Controller 扩展了 Umbraco 的 SurfaceController
- 将其命名为您的名字*SurfaceController*
- 将 [PluginController("CLC")]“注释”(我来自 Java)添加到您的 Controller 中。 CLC 代表国家列表 Controller 。当然,您可以自己起一个名字。
- 将 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/