Using Conditional Logic in Views
One way to make UI modifications is to have conditional logic in views. There is an extension method, IsEnabledForTenant, that can be used to check if a specific property is set to true for the current tenant:
This will look for an option registered using the Options Pattern that was described in the previous post.
Another option is to check for a specific tenant, using the IsTenant extension method:
For the exact same purpose we can also use the <tenant> tag helper:
If we wish to load a partial view, there’s another tag helper just for that, <tenant-partial>:
<tenant-partial tenant=”xyz” name=”xyzView”></tenant-partial>
This will conditionally load the xyzView file if the current tenant is xyz.
Using Different Files
A different approach would be to have different files (in different folders), one for each tenant. Say, for example, that you want to have a different folder per each tenant in your Views\<controller> folder. You just need to call AddTenantLocations when registering the services:
After this, if you have this folder structure:
ASP.NET Core will load the views from the tenant-specific folder, (abc or xyz) and only if it cannot find the files there ASP.NET Core will it resort to the default ones (in Home or Shared).
Finally, if you wish to load static files from a well-known location that refers to the tenant, you can do this:
This is as much as it goes for now for making the UI multitenant with SharedFlat. On the next post I will be talking about data, how to access databases in a multitenant way.