我是asp.net mvc的初学者。我为视图定义了模型,该模型具有每当有更新操作时需要在ApplicationService处理的所有数据。
如何将模型从视图传递给控制器。例如,当我编辑一行并将该行保存到数据库中时,在将数据保存到数据库之前,我需要一些细节来操作该行。 我在模型中具有执行该行中的操作所需的所有必需数据。
@model mymodel.MyViewModel
.
.
.
<script type="text/javascript">
jQuery("#jQGridDemo").jqGrid({
url: 'mycontroller/updatemethod',
datatype: "json",
postData : //i dont know how to pass model to controller here
colNames: ['Id','First Name', 'Last Name', 'Last 4 SSN', 'Department',
'Age', 'Salary', "Address",'Marital Status'],
colModel: [
{ name: '_id', index: '_id', width: 20, stype: 'text' },
{ name: 'FirstName', index: 'FirstName', width: 150 },
{ name: 'LastName', index: 'LastName', width: 150 },
{ name: 'LastSSN', index: 'LastSSN', width: 100 },
{ name: 'Department', index: 'Department', width: 80, align: "right" },
{ name: 'Age', index: 'Salary', width: 80, align: "right" },
{ name: 'Salary', index: 'Salary', width: 80, align: "right" },
{ name: 'Address', index: 'Address', width: 150, sortable: false },
{ name: 'MaritalStatus', index: 'MaritalStatus', width: 100, sortable: false }
],
rowNum: 10,
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption: "List Employee Details"
});
</script>
[ActionVerbs(HttpVerbs.Post)]
Public ActionResult updatemethod(MyViewModel mymodel)
{
// From viewmodel, I have necessary data to validate before calling database update
}