简体   繁体   English

从Asp.NET MVC 5中的Controller继承

[英]Inheritance from Controller in Asp.NET MVC 5

I created a generic controller class 我创建了一个通用控制器类

namespace OxygenFramework.MvcController
{
  public class MvcController<TEntity> : Controller
    where TEntity : class
  {
    public void UpdateModelState(TEntity t)
    {
        ...
    }
  }
}

then I used it as below 然后我用它如下

namespace LeitnerMVC.Controllers
  {
    public class HomeController : MvcController<Account>
     {
    //
    // GET: /Home/
    public ActionResult Index()
    {
        UpdateModelState(t);
        return View();
    }
  }
}

BUT when run mvc application page shows this error 但是当运行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.

after searched in web I found a way for solve it 在网上搜索后,我找到了解决问题的方法

  void Application_Start(object sender, EventArgs e)
    {                 
    ControllerBuilder.Current.DefaultNamespaces.Add("OxygenFramework.MvcController");
    }

But above solution does not work for me !!! 但是上述解决方案对我不起作用! and shows Http 404 error again 并再次显示Http 404错误

When use Controller instead of MvcController page shows without problem !!! 当使用Controller而不是MvcController页面时,显示没有问题!

Can anyone help me ? 谁能帮我 ?

Update : 更新:

after many investigation I understand why this problem occurs but still I dont know how resolve that. 经过多次调查,我了解了为什么会出现此问题,但我仍然不知道如何解决该问题。 WHEN I move source code of MvcController out of my framework assemby (OxygenFramework.MvcController) and move it into MVC project MvcController works but when I refrence MvcController from OxygenFramework assembly MVC shows 404 error !!! 当我将MvcController的源代码移出我的框架assemby(OxygenFramework.MvcController)并将其移入MVC项目时,MvcController可以工作,但是当我从OxygenFramework程序集引用MvcController时,MVC显示404错误! Now I know this problem occur because MvcController is into another assembly but I dont know how solve this problem 现在我知道发生此问题的原因是MvcController进入另一个程序集,但我不知道如何解决此问题

attention : only generic implimentation of MvcController is in OxygenFramework assembly and all of Controller is into the default Controllers folder 注意: OxygenFramework程序集中只有MvcController的一般含义,所有Controller都位于默认的Controllers文件夹中

After many investigation I found problem I want to say @Agat thank you :) 经过大量调查后,我发现了问题,我想对@Agat表示感谢:)

But Solution : I used System.Web.Mvc.dll version 4.0 in my framework but used System.Web.Mvc.dll 5.0 in my MvcApplication ! 但是解决方案:我在框架中使用System.Web.Mvc.dll版本4.0,但在MvcApplication中使用System.Web.Mvc.dll 5.0! This interference causes the 404 error from inheritance :D 这种干扰会从继承中导致404错误:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM