Bind Datatable in Index page in MVC using Dropdownlist value

anil kumar 61 Reputation points
2021-10-20T09:02:18.167+00:00

var filterresult = (from e in employees
select new EmpAttendanceViewModel
{
AId = e.AId,
EmpId = e.Empid,
Name = e.name,
offid = (from att in empAttendances where att.EmpAId == e.AId select e.OffMasId).FirstOrDefault(),
Time = (from att in empAttendances where att.EmpAId == e.AId select (att.TOut - att.TIn).ToString()).FirstOrDefault(),//(t1.TOut - t1.TIn).ToString() //
}).ToList();

I want to bind/filter record and bind to datatable in INdex page using dropdownlist value
when page load it show all record and after that select value from dropdownlist and click on button
than record fill datatable as per selected item

Developer technologies ASP.NET ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-10-21T08:02:06.03+00:00

    According to your description, I suggest you could try to refer to this article to achieve using dropdownlist to filter the row.

    More details ,you could refer to below example:

    View:

    @model List<CoreNormalIssueMVC2.Models.EmpAttendanceViewModel>  
    @{  
        ViewData["Title"] = "DataTableTest";  
    }  
      
    <h1>DataTableTest</h1>  
      
    <div class="container">  
        <br />  
            <table id="example" class="table table-striped table-bordered dt-responsive nowrap" width="100%" cellspacing="0">  
                <thead>  
                    <tr>  
                        <th>AId</th>  
                        <th>EmpId</th>  
                        <th>Name</th>  
                        <th>offid</th>  
                        <th>Time</th>  
                    </tr>  
                </thead>  
                <tbody>  
                    @foreach (var item in Model)  
                    {  
                        <tr>  
      
      
                            <td>@item.AId</td>  
      
                            <td>  
                                @item.EmpId  
                            </td>  
      
                            <td>  
                                @item.Name  
                            </td>  
      
                            <td>  
                                @item.offid  
                            </td>  
                            <td>  
                                @item.Time  
                            </td>  
      
                        </tr>  
      
                    }  
                </tbody>  
                <tfoot>  
                    <tr>  
                        <th>AId</th>  
                        <th>EmpId</th>  
                        <th>Name</th>  
                        <th>offid</th>  
                        <th>Time</th>  
                    </tr>  
                </tfoot>  
            </table>  
        </div>  
    </div>  
    

    jquery

    U9nbN.png

    Result:

    qtn9M.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.