我有一个数据表,其中的数据(来自数据库)正在填充 ajax,我还想要一个带有“详细信息”的新表行来显示所选项目的更多详细信息,但该表只允许来自数据库的数据。这是视图
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#myDataTable').dataTable({
"bProcessing": false,
"bServerSide": true,
"sAjaxSource": 'AjaxDataProvider',
"aoColumns": [
{
"sName": "ID",
},
{ "sName": "Student_naam" },
{ "sName": "klas" },
{ "sName": "adres" },
{ "sName": "woonplaats" },
{ "sName": "details" }
]
})
});
</script>
我在下面有一个表格,上面有一些代码,包括:
<td>
@Html.ActionLink("Details", "Index", "StudentGegevens", new {id = item.studentnr})
</td>
这是我的控制器
public ActionResult AjaxDataProvider(JQueryDataTableParamModel param)
{
var allStudents = hoi.STUDENT.ToList();
IEnumerable<STUDENT> filteredStudents;
if (!string.IsNullOrEmpty(param.sSearch))
{
//Used if particulare columns are filtered
var roepnaamFilter = Convert.ToString(Request["sSearch_1"]);
var adresFilter = Convert.ToString(Request["sSearch_2"]);
var woonplaatsFilter = Convert.ToString(Request["sSearch_3"]);
var klasFilter = Convert.ToString(Request["sSearch_4"]);
//Optionally check whether the columns are searchable at all
var isNameSearchable = Convert.ToBoolean(Request["bSearchable_1"]);
var isAddressSearchable = Convert.ToBoolean(Request["bSearchable_2"]);
var isTownSearchable = Convert.ToBoolean(Request["bSearchable_3"]);
var isClassSearchable = Convert.ToBoolean(Request["bSearchable_4"]);
filteredStudents = hoi.STUDENT.ToList()
.Where(c => isNameSearchable && c.roepnaam.ToLower().Contains(param.sSearch.ToLower())
||
isAddressSearchable && c.adres.ToLower().Contains(param.sSearch.ToLower())
||
isTownSearchable && c.woonplaats.ToLower().Contains(param.sSearch.ToLower())
||
isClassSearchable && c.klas.ToLower().Contains(param.sSearch.ToLower()));
}
else
{
filteredStudents = allStudents;
}
var isNameSortable = Convert.ToBoolean(Request["bSortable_1"]);
var isAddressSortable = Convert.ToBoolean(Request["bSortable_2"]);
var isTownSortable = Convert.ToBoolean(Request["bSortable_3"]);
var isClassSortable = Convert.ToBoolean(Request["bSortable_4"]);
var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);
Func<STUDENT, string> orderingFunction = (c => sortColumnIndex == 1 && isNameSortable ? c.roepnaam :
sortColumnIndex == 2 && isClassSortable ? c.klas :
sortColumnIndex == 3 && isAddressSortable ? c.adres :
sortColumnIndex == 4 && isTownSortable ? c.woonplaats :
"");
var sortDirection = Request["sSortDir_0"]; // asc or desc
if (sortDirection == "asc")
{
filteredStudents = filteredStudents.OrderBy(orderingFunction);
}
else
{
filteredStudents = filteredStudents.OrderByDescending(orderingFunction);
}
var displayedStudents = filteredStudents.Skip(param.iDisplayStart).Take(param.iDisplayLength);
var result = from c in displayedStudents select new[] { Convert.ToString(c.studentnr), c.roepnaam, c.klas, c.adres, c.woonplaats, "Here is the thing I dont know what to fill in" };
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = allStudents.Count(),
iTotalDisplayRecords = filteredStudents.Count(),
aaData = result
},
JsonRequestBehavior.AllowGet);
}
还有一些公共整数
public class JQueryDataTableParamModel
{
public string sEcho { get; set; }
public string sSearch { get; set; }
public int iDisplayLength { get; set; }
public int iDisplayStart { get; set; }
public int iColumns { get; set; }
public int iSortingCols { get; set; }
public string sColumns { get; set; }
}
我想知道我应该在 var Result 中放什么。
除链接外,所有内容均正确显示,我尝试了 Url.Action 之类的方法,但没有运气,它没有返回链接。