脚本:
<script type="text/javascript">
$(document).ready(function () {
$("#grid").jqGrid({
url: '@Url.Action("GetAllCategories", "Admin")',
datatype: "json",
mtype: 'GET',
colNames: ['sno','Kategori Adı', 'Sıra No', 'Vitrin'],
colModel: [
{ name: 'sno', index: 'sno', editable: false, hidden: true },
{ name: 'Name', index: 'Name', editable: true },
{ name: 'OrderNo', index: 'OrderNo', editable: true },
{ name: 'IsShowcase', index: 'IsShowcase', width: 100, editable: true, sortable: false }
],
jsonReader: {
repeatitems: false
},
rowNum: 10,
rowList: [10, 20, 30, 40, 50],
pager: jQuery('#gridpager'),
sortname: 'CategoryName',
viewrecords: true,
sortorder: "asc",
id: "sno",
width: 710,
height: 300,
editurl: '@Url.Action("_EditCategory", "Admin")'
}).navGrid('#gridpager');
});
</script>
控制器
[HttpPost]
public ActionResult _EditCategory(CategoriesViewModel categoriesViewModel)
{
Categories category = entity.Categories.SingleOrDefault(x => x.sno == categoriesViewModel.sno);
category.IsShowcase = categoriesViewModel.IsShowcase;
category.Name = categoriesViewModel.Name;
category.OrderNo = categoriesViewModel.OrderNo;
try
{
entity.Categories.Add(category);
entity.SaveChanges();
}
catch (Exception ex) { }
return PartialView(categoriesViewModel);
}
我调试了它。我不能只发布模型的 sno(sno 是模型和 uniq 的主键)。模型贴了参数,但只有sno没有贴。
我怎样才能做到这一点?谢谢。