Skip to content

MVC Views

Danger

We do not recommend using MVC views for any purpose. Please contact the Suite Team if you are about to do so.

The MVC Module supports loading MVC pre-compiled views. This is mostly useful for security critical applications, like the Users Identity Service, which has the OAuth2 implementation.

Pre-compiled views

When we say pre-compiled views, we mean that, when you build your module .cshtml files will get compiled into a separated .Views.dll file. This is normal ASP.NET behavior.

Suite Application Modules

For Suite Applications, since they are already a csproj SDK of type Microsoft.NET.Sdk.Web, the .Views.dll will get auto-generated if you have view files.

However for the MVC Module to discover your views, you need to explicitly tell it which assemblies are expected to have a .Views.dll file. For example:

C#
public class MyAppModule : SuiteAspNetApplicationModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);

        builder.DependsOn<EndpointsModule, EndpointsModuleOptions>(options =>
        {
            options.AddMvcCompiledViewSource<MyAppModule>();
        });
    }
}

Suite Modules

If the module containing the views is not the Root Module, the csproj will be a Microsoft.NET.Sdk and won't generate views automatically.

If you are creating a new module there's a Template Suite MVC Module that you can use.

However, if you want to add views to an existent module, you need to:

  1. Change the SDK to be Microsoft.NET.Sdk.Razor
  2. Set the AddRazorSupportForMvc to true.

For example:

XML
<Project Sdk="Microsoft.NET.Sdk.Razor">
    <PropertyGroup>
        <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
    </PropertyGroup>

    <ItemGroup>
        <ProjectReference Include="$(FrameworkPath)ITsynch.Suite.Abstractions.AspNet\ITsynch.Suite.Abstractions.AspNet.csproj" />
        <ProjectReference Include="$(ModulesPath)ITsynch.Suite.MvcModule\ITsynch.Suite.MvcModule.csproj" />
    </ItemGroup>

    <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
    </ItemGroup>
</Project>

You'll also need to make the module containing the views, depend on the EndpointsModule:

C#
public class MyAppModule : SuiteAspNetApplicationModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);

        builder.DependsOn<EndpointsModule, EndpointsModuleOptions>(options =>
        {
            options.AddMvcCompiledViewSource<MyAppModule>();
        });
    }
}