Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T4MVC not generating some Actions for one Controller

Tags:

t4mvc

I have a situation where T4MVC is generating everything properly (meaning intellisense shows all areas/controllers/actions and everything compiles), but when I run the code, I get a T4MVC was called incorrectly runtime error.

I've investigated the generated files and discovered that for one controller in my project, only actions in the base class are getting the overridden stub actions generated. For other controllers, all actions are being generated. They all have the same set up, described below.

I have a BaseController class that has some shared code (and inherits from Controller). In the Controllers directory (root of project) I have a number of controllers, all which inherit from BaseController.

I then have several Areas. In each Area, I have the same controllers, each inheriting from the controller of the same name in the root Controllers directory.

Running T4MVC (version 2.6.54), everything works fine except for one controller. The odd thing is that intellisense works for the controller, but chokes when the actual action is referenced (in an ActionLink() call).

I manually added one action in particular into the generated code and there was no error.

So my question is, what would cause T4MVC to not generate all code for a controller? The missing actions are all public virtual ActionResult and the actions themselves work fine. The problem controller has the same issue in all Areas.

Some abbreviated code.

/Controllers/BaseController.cs

namespace MyProject.Controllers
{
    public abstract partial class BaseController : Controller
    {
        protected ISession session;

        public BaseController()
        {
        }

        // other shared methods/actions
    }
}

/Controllers/ActivitiesController.cs (this is the problem controller)

namespace MyProject.Controllers
{
    public partial class ActivitiesController : BaseController
    {
        // for resolving concurrency exceptions
        private Activity userValues;
        private Activity databaseValues;

        public ActivitiesController() : base()
        {
            ViewBag.ControllerName = "Activities";
        }

        // this action is causing the problem used like
        <li>@Html.ActionLink("Activities", MVC.Areas.Module1.Activities.Index())</li> in a view
        public virtual ActionResult Index()
        {
            return View();
        }
    }
}

/Areas/Module1/Controllers/ActivitiesController.cs. This is the whole class

namespace MyProject.Areas.Module1.Controllers
{
    public partial class ActivitiesController : MyProject.Controllers.ActivitiesController
    {
        public ActivitiesController() : base()
        {
            base.currentModule = Modules.Module1;            
        }
    }
}
like image 210
Steve Mallory Avatar asked Dec 30 '25 02:12

Steve Mallory


1 Answers

In case anyone else comes across this I had a similar issue and resulting run-time error message but in a bit different scenario. It was in the RedirectToAction statement at end of a ActionResult method:

RedirectToAction(Edit(id));

The error went away after correcting it to:

RedirectToAction(MVC.[action name].Edit(id));

The error message isn't very intuitive and the suggestion to re-run the custom tool doesn't really help.

like image 135
Ales Potocnik Hahonina Avatar answered Jan 01 '26 20:01

Ales Potocnik Hahonina