Search code examples
aspnetboilerplate

How to understand Multitenancy is enabled or not in view?


We are not using multi-tenancy. When it is disabled most of the tenant related UI gets hidden but in the LinkedAccount page, the user can view the tenancy name(which is Default). We wanted to hide it in the UI. Tried to find a property like IsMultiTenancyEnabled but couldn't find(Actually it is in the IMultiTenancyConfig but not available to razor page). So, how can hide UI elements if Multitenancy is not enabled?

//This is the code we want to hide. 
<div class="form-group">
        <label>@L("TenancyName")</label>
        <input type="text" name="TenancyName" class="form-control" value="@(ViewBag.TenancyName ?? "")" maxlength="@TurkKizilayi.RFL.MultiTenancy.Tenant.MaxTenancyNameLength">
</div>

And there is one thing more: What happens if we hide this code anyway? Should we change the model or app service (Yes)?


Solution

  • For MVC you can inject IMultiTenancyConfig into your view. Here is the final code of what you want;

    @inject IMultiTenancyConfig MultiTenancyConfig
    @using Abp.Configuration.Startup
    @using MyCompanyName.AbpZeroTemplate.Web.Areas.AppAreaName.Models.Common.Modals
    @Html.Partial("~/Areas/AppAreaName/Views/Common/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("LinkNewAccount")))
    
    <div class="modal-body">
        <form name="LinkAccountModalForm" role="form" novalidate class="form-validation">
    
            @if (MultiTenancyConfig.IsEnabled)
            {
                <div class="form-group">
                    <label>@L("TenancyName")</label>
                    <input type="text" name="TenancyName" class="form-control" value="@(ViewBag.TenancyName ?? "")" maxlength="@MyCompanyName.AbpZeroTemplate.MultiTenancy.Tenant.MaxTenancyNameLength">
                </div>
            }
    
            <div class="form-group">
                <label>@L("UserName")</label>
                <input class="form-control" type="text" name="UsernameOrEmailAddress" required maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxEmailAddressLength">
            </div>
    
            <div class="form-group">
                <label>@L("Password")</label>
                <input type="password" name="Password" autocomplete="off" class="form-control" required maxlength="@MyCompanyName.AbpZeroTemplate.Authorization.Users.User.MaxPasswordLength">
            </div>
        </form>
    
    </div>
    
    @Html.Partial("~/Areas/AppAreaName/Views/Common/Modals/_ModalFooterWithSaveAndCancel.cshtml")