Recently I have started to work on show/hide, enable/disable controls based on logged in users role and its assigned permissions. While browsing on the net lot of people have provided to create the custom html helper and also the latest introduced tag helpers.
So, my question is can i show/hide, enable/disable controls using TagHelpers ? or do i need to write html helper only.
Right now I have implemented it as follows using the traditional method
@if (!permissions.CheckPermission("course.coursedetails.mytextbox.visible"))
{
<section class="col col-5">
<label class="label">@objLocalizer["Title"]</label>
<label class="input">
<i class="icon-append fa fa-tag"></i>
@Html.TextBoxFor(model => model.CourseLang.CourseTitle, permissions.CheckPermission ("course.coursedetails.mytextbox.enabled") ? (object)new { @disabled = "disabled", @class = "form-control", @id = "mytextbox" } : new { @class = "form-control", @id = "mytextbox" })
<span asp-validation-for="CourseLang.CourseTitle" class="text-danger"></span>
</label>
</section>
}
As you can see I have checked the required permission in @Html.TextBoxFor
,
However this logic is not applicable on all types of controls like select, label
etc.
So, how can i make a common approach/class to achieve this thing by using tag helper/html helper ?