我创建了一个通用 Controller 类
namespace OxygenFramework.MvcController
{
public class MvcController<TEntity> : Controller
where TEntity : class
{
public void UpdateModelState(TEntity t)
{
...
}
}
}
然后我按如下方式使用它
namespace LeitnerMVC.Controllers
{
public class HomeController : MvcController<Account>
{
//
// GET: /Home/
public ActionResult Index()
{
UpdateModelState(t);
return View();
}
}
}
但是当运行 mvc 应用程序页面时显示此错误
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
在网上搜索后找到了解决的方法
void Application_Start(object sender, EventArgs e)
{
ControllerBuilder.Current.DefaultNamespaces.Add("OxygenFramework.MvcController");
}
但是上述解决方案对我不起作用!并再次显示 Http 404 错误
当使用Controller而不是MvcController时页面显示没有问题!!!
谁能帮我吗?
更新:
经过多次调查,我明白为什么会出现这个问题,但我仍然不知道如何解决。 当我将 MvcController 的源代码移出框架程序集 (OxygenFramework.MvcController) 并将其移至 MVC 项目时,MvcController 可以工作,但是当我从 OxygenFramework 程序集 MVC 引用 MvcController 时,显示 404 错误! 现在我知道发生这个问题是因为 MvcController 进入另一个程序集 但我不知道如何解决这个问题
注意:只有 MvcController 的通用实现位于 OxygenFramework 程序集中 所有的 Controller 都放在默认的 Controller 文件夹中
最佳答案
经过多次调查我发现了问题 我想说@Agat谢谢你:)
但是解决方案: 我在我的框架中使用了 System.Web.Mvc.dll 版本 4.0,但在我的 MvcApplication 中使用了 System.Web.Mvc.dll 5.0! 这种干扰会导致继承的 404 错误:D
关于c# - Asp.NET MVC 5 中 Controller 的继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19879895/