您好我有一个mDataProp DateTime
格式问题。基本上我想在一列中显示日期,在另一列中显示时间。
但据我所知,mDataProp与你的模型直接相关,而后者没有时间属性只是一个adate ......
控制器
var result = from a in data
select new
{
appointmentDate = a.AppointmentDate.ToShortDateString(),//.ToString("g"),
appointmentTime = a.AppointmentDate.ToLocalTime().ToString("t"),
appointmentName = a.AppointmentType.AppName,
appointmentID = a.AppointmentID
};
//Return Json data for Datatable
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = total,
iTotalDisplayRecords = total,
aaData = result
});
查看
<script>
$(document).ready(function () {
var urlRequest = $('#apptTable').data("request-url");
var detailRequest = $('#apptTable').data("detail-url");
$('#apptTable').dataTable({
"bSort": false,
"bServerSide": true,
"sAjaxSource": urlRequest,
"sServerMethod": "POST",
"bProcessing": true,
"bFilter": false,
"aoColumns": [
{ "mDataProp": "appointmentDate" },
{ "mDataProp": "appointmentDate" },
{ "mDataProp": "appointmentName" },
{
"mDataProp": "appointmentID",
"fnRender": function (oObj) {
return '<a href=\"' + detailRequest + '/' + oObj.aData.appointmentID + '\">Details</a>';
}
}
]
});
});
</script>
我无法在控制器中创建名为appointmentDate
的第二个变量,因此我必须在视图中进行格式化。
有什么想法吗?