我知道这个问题已被问过好几次了。包括这个特定的post
我认为我做的一切都是正确的,但我无法获得第一列的价值。
http://localhost/Users/Details/[missing]
var InitiatizeUser = function() {
return {
init: function() {
var oTable = $('#users').dataTable({
"dom": "flt<'row DTTTFooter'<'col-sm-6'i><'col-sm-6'p>>",
"aaSorting": [
[1, 'asc']
],
"language": {
"search": "",
"sLengthMenu": "_MENU_",
"oPaginate": {
"sPrevious": "Prev",
"sNext": "Next"
}
},
"aoColumns": [{
"bVisible": false,
"bSearchable": false,
"bSortable": false,
},
null,
null,
null,
null, {
mData: 0,
"bSearchable": false,
"bSortable": false,
sClass: "alignCenter",
"mRender": function(data, type, full) {
return "<a href='/Details/'" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Details'><i class='fa fa-info-circle'></i></a>  <a href='/Edit/'" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Edit'><i class='fa fa-pencil-square-o'></i></a>  <a href='/Delete/'" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Delete'><i class='fa fa-trash-o'></i></a>";
}
}
]
});
}
}
}();
<table class="table table-bordered table-hover table-striped" id="users">
<thead class="bordered-darkorange">
<tr role="row">
<th>
@Html.LabelFor(model => model.AppUsers[0].Id)
</th>
<th>
@Html.LabelFor(model => model.AppUsers[0].Name)
</th>
<th>
@Html.LabelFor(model => model.AppUsers[0].Email)
</th>
<th>
@Html.LabelFor(model => model.AppUsers[0].Group)
</th>
<th>
@Html.LabelFor(model => model.AppUsers[0].Role)
</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach (var user in @Model.AppUsers) {
<tr>
<td>
@Html.Raw(user.Id)
</td>
<td>
@Html.Raw(user.Name)
</td>
<td>
@Html.Raw(user.Email)
</td>
<td>
@Html.Raw(user.Group)
</td>
<td>
@Html.Raw(user.Role)
</td>
<td></td>
</tr>
}
</tbody>
</table>
有人可以帮帮我吗?
感谢。
答案 0 :(得分:4)
您有额外的单引号,请使用以下代码:
"mRender": function(data, type, full) {
return "<a href='/Details/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Details'><i class='fa fa-info-circle'></i></a>  <a href='/Edit/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Edit'><i class='fa fa-pencil-square-o'></i></a>  <a href='/Delete/" + data + "' class='btn icon-only shiny btn-palegreen btn-xs' title='Delete'><i class='fa fa-trash-o'></i></a>";
}