gpt4 book ai didi

c# - 从 Asp.NET MVC 5 中的 Controller 继承

转载 作者:行者123 更新时间:2023-11-30 22:12:10 28 4
gpt4 key购买 nike

我创建了一个通用 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 都在默认的 Controllers 文件夹中

最佳答案

经过多次调查,我发现了问题我想说@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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com