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
2- i create reference file table and his model on project and this data on table referencefileCode:public class Employee { [key] public int EmployeeId { get; set; } public string EmployeeName { get; set; } }
when call methodCode:code TableName FieldName 1 Employees EmployeeId 2 Employees EmployeeName
it show all data from reference file table success but if input type is hidden it show also dataCode:@await Component.InvokeAsync("GetReference", new { TableName = "Employees" })
<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> } }


Reply With Quote
