我想在一个模型中捕捉旧值, 这样我就可以在提交后与新值进行比较, 并创建用户更改的审计日志 。
我猜是用隐藏的输入框来做,其中含有重复的旧价值属性,这是一种方法。 但想知道是否有其他好的替代方法吗?
谢谢 谢谢
我想在一个模型中捕捉旧值, 这样我就可以在提交后与新值进行比较, 并创建用户更改的审计日志 。
我猜是用隐藏的输入框来做,其中含有重复的旧价值属性,这是一种方法。 但想知道是否有其他好的替代方法吗?
谢谢 谢谢
在保存方法中,只需从数据库 < 坚固> 中获取原始对象,然后保存这些更改,然后您有新旧的数值可以比较? :
这听起来像标准审计。你不应该担心什么改变了,什么改变了只是抓住了一切,谁做了改变。除非有某种实时报告需要做。
<强 > 可能的审计执行: 强 >
< a href=> "http://elegantcode.com/2009/11/11/cqrs-la-greg-young/" rel="nofollow" >CQRS , 简而言之,它跟踪特定对象的每一个变化。 其下端是它是一个更需要执行的架构。
滚动分类账。在数据库中,每插入一个新行。当前行用于显示目的,但每次更新后,将插入新行。
另一种办法是将其保存在审计表格中。
所有人完成我们的任务
您也可以将原始模型存储在视图袋中, 并做类似的事情...
// In the controller
public ActionResult DoStuff()
{
// get your model
ViewBag.OriginalModel = YourModel;
return View(YourModel);
}
// 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);
}
我还没有机会测试这个,
Mattytommo说什么才是首选方法
建立新实体的新观点模式
public ActionResult Edit(int id) {
var entity = new Entity(id); // have a constructor in your entity that will populate itself and return the instance of what is in the db
// map entity to ViewModel using whatever means you use
var model = new YourViewModel();
return View(model);
}
后回的更改
[HttpPost]
public ActionResult Edit(YourViewModel model) {
if (ModelState.IsValid) {
var entity = new YourEntity(model.ID); // re-get from db
// make your comparison here
if(model.LastUserID != entity.LastUserID // do whatever
... etc...
}
return View(model);
}
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!