0

Is it possible to use T4MVC when The Controllers and Models are in a different Library to the Views?

For example,

  • Namespace.Common.MVC

which contains the Controllers and Models, which is referenced by

  • Namespace.MvcApplication1
  • Namespace.MvcApplication2

which contains the Views.

Installing the nuget T4MVC package into Common.MVC and MvcApplication1 works fine, but when trying to use MVC. on a View there is an error that MVC exists in multiple namespaces, which is logical.

Is there a way around this?

NikolaiDante
  • 18,469
  • 14
  • 77
  • 117

1 Answers1

1

Just like any C# code, if you are trying to use a type whose name exists in multiple namespaces you will need to provide some help to the compiler so that it can figure out which of the types you are referring to.

The options in this case are:

  • Fully qualify the MVC type name e.g. in your views use Namespace.Common.MVC.MVC
  • Change the name of the generated type in each of the projects. E.g. open the T4MVC.tt.settings.xml file in your common project and change the value of the <HelpersPrefix> element from MVC to something unique such as MVCCommon. In your views you can now reference it as MVCCommon.Something
Jared Russell
  • 10,804
  • 6
  • 30
  • 31