首先,我有 3 个输入文本框(日、月、年)。我让 Json 从我的控制器返回,我用 jquery 做了一个键和值绑定函数。问题是我不知道如何将日期时间值拆分为日、月、年并绑定到我的输入,因为日期时间值看起来像
EntryDate: "/Date(940786200000)/"
我的控制器
[HttpGet]
public ActionResult getBookById(int? id)
{
TB_EnglishBooks tbook = db.TB_EnglishBooks.Where(x => x.ItemID == id).FirstOrDefault();
return Json(tbook, JsonRequestBehavior.AllowGet);
}
我的 HTML 视图
<input class="form-control" id="Day" type="text" placeholder="Day" style="width: 94px;">
<input class="form-control" id="Month" type="text" placeholder="Month" style="width: 94px;">
<input class="form-control" id="Year" type="text" placeholder="Year" style="width: 94px;">
我的绑定函数
function bindcontrol(data) {
$.each(data, function (key, value) {
$("#mymodal").modal('show');
if (value == true || value == false) {
$("#addform").find("input[type='checkbox'][name='" + key + "']").prop("checked", value);
}
else {
$("#addform").find("input[name='" + key + "']").val(value);
$("#addform").find("textarea[name='" + key + "']").val(value);
$("#addform").find("select[name='" + key + "']").val(value);
}
})
}