这是一个安全的程序,可以将我的模型中的近100个字段保存到视图包中。对于审计,我只需要将修改后的值存储到数据库中。请帮助。
// In the View
<input type="hidden" name="originalModel" value="@Html.Raw(Json.Encode(ViewBag.OriginalModel));" />
// In the controller's post...
[HttpPost]
public ActionResult DoStuff(YourModel yourModel, string originalModel)
{
// yourModel will be the posted data.
JavaScriptSerializer JSS = new JavaScriptSerializer();
YourModel origModel = JSS.Deserialize<YourModel>(originalModel);
}
编辑:
{"UserKey":1,"FirstName":"xxxx","LastName":"yyyyy","MiddleInitial":"Ee","EmployeeId":null};
originalModel字符串包含在值之上。