我有一个简单的网格,它有 4 列来自数据库:ID、名称、CreationDate、ModificationDate。所有这些字段都会显示,但只有名称是可编辑的。ID 和日期显示为纯文本。
我遇到的问题是修改记录时。只有名称字段被传递到服务器端。CreationDate 作为默认值发送为 01/01/0001,而不是当前具有的值。
这是我的脚本:
<script type="text/javascript">
$(function () {
$("#departamentos").jqGrid({
url: "@Url.Action("List")",
datatype: "json",
mtype: "GET",
colNames: ["@Html.DisplayNameFor(model => model.dep_id)",
"@Html.DisplayNameFor(model => model.dep_nombre)",
"@Html.DisplayNameFor(model => model.dep_creado_el)",
"@Html.DisplayNameFor(model => model.dep_modificado_el)",
" "],
colModel: [
{ name: "dep_id", index: "dep_id", key : true, sortable:false, editable:false, editoptions:{readonly:true,size:10}, width: 90 },
{ name: "dep_nombre", index: "dep_nombre", editable:true, width: 250 },
{ name: "dep_creado_el", index: "dep_creado_el", width: 100, align: "center", formatter: "date" },
{ name: "dep_modificado_el", index: "dep_modificado_el", width: 100, align: "center", formatter: "date" },
{ name: 'acciones', width: 58, fixed: true, sortable: false, resize: false, formatter: 'actions', formatoptions: { keys: true } }
],
jsonReader: {
repeatitems: false
},
pager: "#pager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "dep_nombre",
sortorder: "asc",
viewrecords: true,
gridview: true,
autoencode: true,
multiselect: true,
caption: "Departamentos",
editurl: "@Url.Action("AjaxEdit")",
});
$("#departamentos").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true });
$.jgrid.edit.addCaption = "Agregar Departamento";
$.jgrid.edit.editCaption = "Modificar Departamento";
$.jgrid.edit.saveData = "¡El departamento fue modificado! ¿Almacena los cambios?";
$.jgrid.formatter.date.newformat = 'd-m-Y H:i';
});
</script>
任何帮助将不胜感激谢谢 Jaime