How to display data for label from database and when input type is hidden not display
Problem
How to display data for label from database on view and when input type is hidden not display data for this control or property from database ?
1- suppose I have model Employee as following
Code:
public class Employee
{
[key]
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
}
2- i create reference file table and his model on project and this data on table referencefile
Code:
code TableName FieldName
1 Employees EmployeeId
2 Employees EmployeeName
when call method
Code:
@await Component.InvokeAsync("GetReference", new { TableName = "Employees" })
it show all data from reference file table success but if input type is hidden it show also data
<input type="hidden" asp-for="EmployeeId" />
in case of EmployeeId is hidden must not show EmployeeId meaning result must show
EmployeeName only
I have view component return list of data based on table name Reference File
what i need when control or property is hidden on view call function invokeasync show data not hidden on view and exist on database
How to do that please ?
pseudo code
if(field exist on reference file table && is not hidden on view ui
show it as label text
else
not display it
what I have Try
Code Details of view component
Code:
public class GetReferenceViewComponent : ViewComponent
{
private readonly TabDbContext _context;
public GetReferenceViewComponent(TabDbContext context)
{
_context = context;
}
public async Task<IViewComponentResult> InvokeAsync(string TableName)
{
var result = _context.ReferenceFiles.Where(r => r.TableName == TableName).ToList();
ViewBag.GetReference = result;
return View();
}
on view component view shared/getreference/Default.cshtml
@foreach (var itemes in ViewBag.GetReference)
{
<ul>
<li> @itemes.FieldName </li>
</ul>
}
}