Inheritance from Controller in Asp.NET MVC 5

R R

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

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

When use Controller instead of MvcController page shows without problem !!!

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 !!! Now I know this problem occur because MvcController is into another assembly but I dont know how solve this problem

attention : only generic implimentation of MvcController is in OxygenFramework assembly and all of Controller is into the default Controllers folder

R R

After many investigation I found problem I want to say @Agat thank you :)

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 ! This interference causes the 404 error from inheritance :D

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling Classic ASP from ASP.NET MVC5 Controller on the same server

From Dev

How to return XML from an ASP.NET 5 MVC 6 controller action

From Dev

post data to controller from view using viewModel classes -ASP.NET MVC5

From Dev

How to pass a List from a View to a Controller ASP.NET MVC5

From Dev

Pass entire object from view to controller in ASP.NET MVC 5

From Dev

How to get access token in Asp.net MVC5 Controller action from OwinContext

From Dev

ASP.NET MVC 5 calling controller method from Javascript Error

From Dev

Send data from textbox with ajax to asp.net mvc 5 controller

From Dev

How to generate a view from a controller in VS 2015 ASP.NET 5 MVC6

From Dev

How do I deserialize from JSON to an abstract parameter on an ASP.NET MVC 5 controller

From Dev

How to get data from a html5 web form on a controller asp.net mvc?

From Dev

How do I pass DateTime parameters from View to Controller in ASP.net MVC5?

From Dev

Asp.Net MVC5 - Passing Nested model from View to Controller through jqGrid Add dialogue

From Dev

Send data from textbox with ajax to asp.net mvc 5 controller

From Dev

Can Not Set Toastr Message From Controller in ASP.NET MVC 5

From Dev

Passing empty list from controller to controller asp.net mvc

From Dev

Passing empty list from controller to controller asp.net mvc

From Dev

ASP.NET MVC post to controller action from same controller

From Dev

ASP.NET 5 / MVC 6 Ajax post Model to Controller

From Dev

Is it possible to have an anonymous controller in asp.net MVC 5?

From Dev

How to disable default route on controller ASP.NET MVC 5

From Dev

ASP.NET MVC5: Unit Testing a controller with a session

From Dev

Asp.Net MVC 5 has no Add New Controller?

From Dev

Asp.net MVC 5 not calling controller create method

From Dev

Controller for partial view in asp.NET 5 MVC

From Dev

Controller for partial view in asp.NET 5 MVC

From Dev

Is it possible to have an anonymous controller in asp.net MVC 5?

From Dev

ASP.NET MVC5 RoutePrefix controller name

From Dev

ASP.NET MVC 5 dynamic controller routes

Related Related

  1. 1

    Calling Classic ASP from ASP.NET MVC5 Controller on the same server

  2. 2

    How to return XML from an ASP.NET 5 MVC 6 controller action

  3. 3

    post data to controller from view using viewModel classes -ASP.NET MVC5

  4. 4

    How to pass a List from a View to a Controller ASP.NET MVC5

  5. 5

    Pass entire object from view to controller in ASP.NET MVC 5

  6. 6

    How to get access token in Asp.net MVC5 Controller action from OwinContext

  7. 7

    ASP.NET MVC 5 calling controller method from Javascript Error

  8. 8

    Send data from textbox with ajax to asp.net mvc 5 controller

  9. 9

    How to generate a view from a controller in VS 2015 ASP.NET 5 MVC6

  10. 10

    How do I deserialize from JSON to an abstract parameter on an ASP.NET MVC 5 controller

  11. 11

    How to get data from a html5 web form on a controller asp.net mvc?

  12. 12

    How do I pass DateTime parameters from View to Controller in ASP.net MVC5?

  13. 13

    Asp.Net MVC5 - Passing Nested model from View to Controller through jqGrid Add dialogue

  14. 14

    Send data from textbox with ajax to asp.net mvc 5 controller

  15. 15

    Can Not Set Toastr Message From Controller in ASP.NET MVC 5

  16. 16

    Passing empty list from controller to controller asp.net mvc

  17. 17

    Passing empty list from controller to controller asp.net mvc

  18. 18

    ASP.NET MVC post to controller action from same controller

  19. 19

    ASP.NET 5 / MVC 6 Ajax post Model to Controller

  20. 20

    Is it possible to have an anonymous controller in asp.net MVC 5?

  21. 21

    How to disable default route on controller ASP.NET MVC 5

  22. 22

    ASP.NET MVC5: Unit Testing a controller with a session

  23. 23

    Asp.Net MVC 5 has no Add New Controller?

  24. 24

    Asp.net MVC 5 not calling controller create method

  25. 25

    Controller for partial view in asp.NET 5 MVC

  26. 26

    Controller for partial view in asp.NET 5 MVC

  27. 27

    Is it possible to have an anonymous controller in asp.net MVC 5?

  28. 28

    ASP.NET MVC5 RoutePrefix controller name

  29. 29

    ASP.NET MVC 5 dynamic controller routes

HotTag

Archive