我有一个主mvc项目和一个区域
该区域使用主项目中的共享_Layout.cshtml。在共享导航中,有一个RenderPartial("GlobalNavigation",“导航”),它调用主项目中的控制器“导航”。所以我得到了这个错误
The IControllerFactory 'abc.NinjectControllerFactory' did not return a controller for the name 'Navigation'.我猜这是因为视图在区域中调用了控制器“导航”,但是控制器“导航”在主项目中。我该如何解决这个问题呢?
_Layout.cshtml
<div id="global-nav">
@{ Html.RenderAction("GlobalNavigation", "Navigation"); }
</div>发布于 2013-08-03 01:51:46
试试这个:
<div id="global-nav">
@{ Html.RenderAction("GlobalNavigation", "Navigation", new { area = "" }); }
</div>发布于 2013-08-03 01:56:34
如果你只是加载一个分部的,为什么你需要控制器参数?在控制器方法中是否构建了逻辑?
试试看:
@{ Html.RenderAction("GlobalNavigation"); }否则,我建议在你的项目中使用HTML助手来构建我们的主导航。
例如:
PROJECT.Web.ExtensionMethods.HtmlExtensions中的Helper
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace OHTP.Web.ExtensionMethods
{
public static class HtmlExtensions
{
public static MvcHtmlString NavMenuLink(this HtmlHelper helper, string linkText, string actionName, string controlName, string activeClassName)
{
if (helper.ViewContext.RouteData.Values["action"].ToString() == actionName &&
helper.ViewContext.RouteData.Values["controller"].ToString() == controlName)
{
var menuLink = helper.ActionLink(linkText, actionName, new { Controller = controlName }, new {Class = activeClassName});
return menuLink;
}
return helper.ActionLink(linkText, actionName, controlName);
}
}
}然后在partial中调用它
<%= Html.NavMenuLink("Copy to display", "ControllerName", "Link", "class") %>https://stackoverflow.com/questions/18022806
复制相似问题