我的Razor视图我有如下的模板
@helper EditLink(SampleEmployeeModel data)
{
<b>
@Html.ActionLink("Edit", "Edit", new { id =data.ID }, new { @class = "modal_link" })
</b>
}
然后我在我的网格控件中使用这个模板,如下所示。Grid Helper方法基于JQuertDataTable工作。
@(
Html.Grid<SampleEmployeeModel>()
.SetName("GridEmployeeServerSide")
.Columns(columns =>
{
columns.Bound(b => b.ID).EnableSearch(false);
columns.Bound().Template(o => EditLink(o)).SetTitle("Edit");
})
.Pageable(a => a.SetPageType(PageType.full_numbers))
.DataSource(a =>
{
a.Read(read => read.Action("RRDLDataTableAjaxData"));
a.ServerSideProcessing(true);
})
)
RRDLDataTableAjaxData应返回如下所示的记录
[
{"ID":1,"Edit":"<b>rn<a class="modal_link" href="/Samples/Edit/1">Edit</a>rn</b>rn"},
{"ID":2,"Edit":"<b>rn<a class="modal_link" href="/Samples/Edit/2">Edit</a>rn</b>rn"},
{"ID":3,"Edit":"<b>rn<a class="modal_link" href="/Samples/Edit/3">Edit</a>rn</b>rn"}
]
当网格第一次加载时,我得到了预期的结果,如果我转到第二页,它不会返回预期的JSon。
Helper方法如何生成HTML网格它将以下代码写入Razor视图
<table class="table table-striped nowrap dt-responsive" data-rrdl-grid="" id="RRDLGrid21V52" width="100%">
<thead>
<tr>
<TH></TH>
<TH></TH>
</tr>
</thead>
<tbody></tbody>
</table>
<script type='text/javascript'>
var dataTable_GridEmployeeServerSide_Option = {
"columns": [
{
"targets": 1,
"defaultContent": "",
"data": "ID",
"title": "ID",
"visible": true
},
{
"targets": 2,
"defaultContent": "",
"data": "Edit",
"searchable": true,
"title": "Edit",
"visible": true
}
],
"dom": "<'table-header-row' <'dom-left' ><'dom-center' ><'dom-right' lp>>t",
"autoWidth": false,
"deferRender": true,
"info": false,
"lengthChange": false,
"ordering": true,
"paging": true,
"processing": false,
"searching": false,
"serverSide": true,
"stateSave": false,
"ajax": {
"contentType": "application/json; charset=utf-8",
"url": "../Samples/RRDLDataTableAjaxData",
"dataType": "json",
"dataSrc": "data"
},
"destroy": false,
"orderClasses": false,
"orderMulti": false,
"pageLength": 10,
"pagingType": "full_numbers",
"scrollCollapse": false,
"language": {
"paginate": {
"first": "<i class="icon-left"></i><i class="icon-left"></i>",
"last": "<i class="icon-right"></i><i class="icon-right"></i>",
"next": "<i class="icon-right"></i>",
"previous": "<i class="icon-left"></i>"
}
},
"OddRowColor": null,
"EvenRowColor": null,
"FixedRowHeight": 0,
"HighlightSearchText": false,
"SelectCheckBox": false,
"RowTemplate": null
}
$(document).ready(function () {
_DataTable(GridEmployeeServerSide);}
)
</script>
我的问题是当用户单击第2页时,如何将EditLink传递到帮助服务器。
错误显示了导致错误的不同属性。显然是ApplicationInstance
导致了循环引用。它与提供的代码片段无关。
根据Json.Net文档,您可以使用以下设置来避免循环引用问题:
var jsonSerializerSettings = new JsonSerializerSettings
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects
};