Jquery 如何在asp.mvc中自动填充搜索栏?我确实有action方法中的json对象列表
我有一个对象列表,当用户输入数据时,我需要将它们调用到搜索栏。我尝试过jquery,但没有成功。我需要知道如何将列表对象连接到视图。Juery提供了用于筛选数据的内置方法 您可以使用jquery.DataTable方法 HomeController.csJquery 如何在asp.mvc中自动填充搜索栏?我确实有action方法中的json对象列表,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我有一个对象列表,当用户输入数据时,我需要将它们调用到搜索栏。我尝试过jquery,但没有成功。我需要知道如何将列表对象连接到视图。Juery提供了用于筛选数据的内置方法 您可以使用jquery.DataTable方法 HomeController.cs [HttpGet] public ActionResult Index() { return View(); } [HttpPost]
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Data()
{
List<Student> st = (from stud in this.studDBContext.students select stud).ToList();
return Json(new { data = st });
}
Index.cshtml
@model IEnumerable<TestCore.Models.Student>
@{
ViewData["Title"] = "Index";
}
<table class="table" id="studentdatatable">
<thead>
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
Address
</th>
<th>
ImageCaption
</th>
<th>
ImageDescription
</th>
<th>
ImageName
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
@* Load datatable css *@
<link href="//cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" rel="stylesheet" />
@* Load datatable js *@
<script src="//cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#studentdatatable').DataTable({
ajax: {
url: "/Home/Data",
type: "POST",
contentType: "application/json",
dataType: "json",
data: function (data) {
console.log(data);
return JSON.stringify(data);
}
},
columns: [
{ data: "id" }, //first letter be small
{ data: "name" },
{ data: "address" },
{ data: "imageCaption" },
{ data: "imageDescription" },
{ data: "imageName" }
]
});
});
</script>
您能提供到目前为止您所拥有的吗?您是否检查了jquery自动完成功能: