[英]How to storage data return from Aspnet MVC and filter it
我在过滤从服务器端返回的数据时遇到问题。 这个想法是存储列表 model 并从该列表的搜索输入中过滤数据。 所有这些都不需要从 controller 更新数据。 我只想通过带有初始初始化列表model的onlick事件过滤它。 有没有办法让它与 MVC 一起工作。 我对 react 和 angular 非常熟悉。 作为反应,我可以这样做:
var oldList = ...array;
array.filter(x => x.id === id && x.name === name)
感谢所有的帮助!
这是我的代码:
@model IEnumerable<Safetrac.Models.UserModel>
@{
ViewBag.Title = "User Page";
}
<script src="~/Scripts/filter.js"></script>
<div class="row">
<div class="container">
First name: <input type="text" id="firstName" />
SurName: <input type="text" id="surName" />
Email: <input type="text" id="email" />
Date Created: <input type="date" id="createdDate" />
<button type="button" class="btn-primary" onclick="Filter()">Filter</button>
<br />
</div>
</div>
<div class="row">
<div class="container">
<h2>Users Record</h2>
<div class="table-responsive">
<table class="table table-bordered table-condensed table-striped table-hover sortable">
<thead>
<tr class="danger">
<th data-firstsort="desc">Id</th>
<th data-firstsort="desc">Name</th>
<th data-firstsort="desc">Email</th>
<th data-firstsort="desc">Date Created</th>
</tr>
</thead>
@foreach (var item in Model)
{
<tr>
<td>@item.Id</td>
<td>@item.Name</td>
<td>@item.Email</td>
<td>@item.DateCreated</td>
</tr>
}
</table>
</div>
</div>
</div>
Onlick 过滤器事件:
//Function for getting the Data Based upon Employee ID
function Filter() {
var firstName = document.getElementById("id").value;
var surName = document.getElementById("name").value;
var email = document.getElementById("email").value;
var createdDate = document.getElementById("createdDate").value;
//filter here ?
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.