我的資料表只顯示
我的資料表只顯示
以下是資料表顯示的內容這是我在EmployeeSettings控制器上的代碼,用于從資料庫表中獲取資料。我已經嘗試將其轉換為字串或日期時間,但會出現錯誤,如無法將System.TimeSpan轉換為字串/日期時間
。 public ActionResult GetData()
{
var employeesetting = (from es in db.EmployeeSettingss.ToList()
join e in db.Employees.ToList() on es.EmployeeIdequals e.Id
select new EmployeeSettingsListModel
{
Id = es.Id,
EmployeeName = e.FirstName " "/span> e.MiddleName " "/span> e.LastName。
EmployeeIn = es.EmployeeIn,
EmployeeOut = es.EmployeeOut,
});
return Json(new { data = employeesetting.ToList() }, JsonRequestBehavior.AllowGet) 。
}
這是我的視圖,我宣告了一些ajax來加載我的表格。
@using PayrollWeb.Models
@model PayrollWeb.Models.EmployeeSettingsFormModel
@{
ViewBag.Title = "AddOrEdit"/span>。
Layout = "~/Views/Shared/_Layout.cshtml"。
}
@using (Html.BeginForm("AddOrEdit"/span>, "EmployeeSettings"/span>, FormMethod. Post, new { onsubmit = "return SubmitFormEmployeeSettings(this)" })
{
@Html.HiddenFor(model => model.Id)
<h1 style="text-align: center;"><span class="fa-gears"></span> Settings</h1>
<div class="employee-form">
@*<div class="form-group">
@Html.LabelFor(x => x.EmployeeCode, new { @class = "form-label"/span> })
@Html.TextBoxFor(x => x.EmployeeCode, new { @class = "form-control", @id = "employeeid" })
</div>*@
<div class="form-group">
@Html.LabelFor(x => x.EmployeeId, new { @class = "form-label"/span>, @style = "color:white;" })
@Html.DropDownListFor(x => x.EmployeeId, Model.Employees, "", new { @class = "form-controll" })
</div>
<div class="form-group">
@Html.LabelFor(x => x.EmployeeIn, new { @class = "form-label"/span>, @style = "color:white;" })
@Html.TextBoxFor(x => x.EmployeeIn, new { @class = "form-control", @type = "time", @id = "employeesin" })
</div>
<div class="form-group">
@Html.LabelFor(x => x.EmployeeOut, new { @class = "form-label"/span>, @style = "color:white;" })
@Html.TextBoxFor(x => x.EmployeeOut, new { @class = "form-control", @type = "time", @id = "employeesout" })
</div>
@*<div class="form-group">
@Html.LabelFor(x => x.AllowOT, new { @class = "form-label" })
@Html.TextBoxFor(x => x.AllowOT, new { @class = "form-control" })
</div>*@
<div class="form-group">
<標簽 class="control-label" style="color:white;" >
允許的加時賽
</label>
<div>
<標簽 class="checkbox-inline">
@Html.CheckBox("YES", false, new { @class = "test" })
是
</label>
</div>
</div>
<div class="form-group">
@Html.LabelFor(x => x.SalaryPerDay, new { @class = "form-label"/span>, @style = "color:white;" })
@Html.TextBoxFor(x => x.SalaryPerDay, new { @class = "form-controll" })
</div>
<div class="form-group">
@Html.LabelFor(x => x.WorkDays, new { @class = "form-label"/span>, @style = "color:white;" })
@Html.TextBoxFor(x => x.WorkDays, new { @class = "form-controll" })
</div>
<div class="form-group">
<input type="submit" value="submit" class="btn btn-primary" />
<input type="reset" value="Reset" class="btn btn-primary" />
</div>
</div>
<table id="EmployeeSettingsTable" class="display table table-striped" style="width: 100" >
<thead>
<tr>
<th>員工姓名</th>
<th>員工在</th>
<th>員工離職</th>
<th></th>
</tr>
</thead>
</table>
<a href="@Url. Action("Index", "Payroll")"> < span class="fa fa-backward"></span> 回傳儀表板</a>。
}
<script type="text/javascript">
//para hindi double check sa checkbox。
//$(document).ready(function () {)
//$(".test").on('change', function () {)
// $(".test").not(this).prop('checked', false);
// });
//});
var dataTable;
$(function () {
dataTable = $('#EmployeeSettingsTable').DataTable({
"ajax": "@Url.Action("getdata", "EmployeeSettings")"。
"列": [
{ "data": "EmployeeName" }。
{ "data": "EmployeeIn" },
{ "資料": "EmployeeOut" },
{
"data": "Id", "render": 函式(data) {
return "<a class='btn btn-default btn-sm' onclick=PopUpForm('@Url. Action("AddOrEdit","EmployeeSettings")/" data ")>。 <i class='fa fa-pencil'></i>編輯</a> <a class='btn btn-danger btn-sm' style='margin-left: 5px;' onclick=Delete(" data ")><i class='fa-trash'></i> Delete</a>"。
},
"orderable": false,
"可搜索": false,
"width": "150px"。
}
],
"語言": {
"emptyTable": "沒有找到資料": "空表": "沒有找到資料"function SubmitFormEmployeeSettings(form) {
$.validator.unobtrusive.parse(form)。
if ($(form).valid()) {
$.ajax({
型別。"POST"/span>,
url: form.action,
data: $(form).serialize(),
success: function (data) {
if (data.success) {
PopUp.dialog('close')。
dataTable.ajax.reload()。
$.notify(data.message, {
globalPosition。"top center",
類名。"success"。
})
}
}
});
}
return false。
}
</script>
這是我的模型。
using System;
using System.Collections.Generic;
namespacePayrollWeb.Models
{
public class EmployeeSettingsListModel : BaseModel
{
public string EmployeeName { get; set; }
public TimeSpan EmployeeIn { get; set; }
public TimeSpan EmployeeOut { get; set; }
}
我不知道為什么當涉及到TimeSpan的時候,datatable只顯示Obj Obj。謝謝你!
uj5u.com熱心網友回復:
嘗試 :
....
var rawData = mployeesetting.ToList().select (b=>new)
{
Id = b.Id,
EmployeeName = b.EmployeeName,
EmployeeIn = b.EmployeeIn.ToString("g"/span>)。
EmployeeOut = b.EmployeeOut.ToString("g")。
});
return Json(new { data = rawData }, JsonRequestBehavior.allowGet);
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/320359.html
標籤:
上一篇:我如何在ASPMVC中根據輸入的employeeid和startdate到enddate對所有的資料庫列進行添加/求和?
