Click here to Skip to main content
13,863,289 members
Rate this:
Please Sign up or sign in to vote.
How to display Notexist text in case of fieldName of table not on Referencefile table ?

public class ReferenceFile
 public int Code { get; set; }
 public string TableName { get; set; }
 public string FieldName { get; set; }



Code TableName FieldName 

1    Employees EmployeeId 
2    Employees EmployeeName 

Result I need
(Age)Notexist (show not exist in case i have model employee have age property but not exist on table reference )
<div class="row">
    <div class="col-md-4">
        <form asp-action="Create">
@await Component.InvokeAsync("GetReference", new { TableName = "Employees" }) }
            <div asp-validation-summary="ModelOnly" class="text-danger"></div>
            <div class="form-group">
                <input asp-for="EmployeeId" class="form-control" />
                <span asp-validation-for="EmployeeId" class="text-danger"></span>
            <div class="form-group">
                <input asp-for="EmployeeName" class="form-control" />
                <span asp-validation-for="EmployeeName" class="text-danger"></span>
            <div class="form-group">
                <input asp-for="Age" class="form-control" />
                <span asp-validation-for="Age" class="text-danger"></span>

What I have tried:

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();
and under shared/Components/GetReference/Default.cshtml
I put following code to get text based on fieldname of reference file table
@foreach (var itemes in ViewBag.GetReference)

and on index view I call as following :

 @await Component.InvokeAsync("GetReference", new { TableName = "Employees" }) }

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190214.1 | Last Updated 11 Feb 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100