none
How to display data for label from database and when input type is hidden not display data for this control or property from database ? RRS feed

  • Question

  • 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

    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	TableName	FieldName
    1	Employees	EmployeeId
    2	Employees	EmployeeName

    when call method 

    @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

    Code Details of view component

     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> } }
    Friday, February 15, 2019 3:28 PM

All replies

  • You don't have an ADO.NET Entity Framework issue. You have HTML issues concerning hidden data, which can be addressed at ASP.NET forums.

    https://forums.asp.net/

    Friday, February 15, 2019 7:55 PM