Should an input model for creating or updating entities have an ID field to identify the entity, or should your edit action accept an ID parameter?
Compare
Input Model
[HttpPost]
public ActionResult(EntityInputModel input)
{
var entity = _unitOfWork.CurrenSession.Get<MyEntity>(input.Id);
// do editing
// ...
}
Action Parameter
[HttpPost]
public ActionResult(Guid id, EntityInputModel input)
{
var entity = _unitOfWork.CurrenSession.G开发者_如何学Goet<MyEntity>(id);
// ...
}
Personally I prefer the first. I always define a specific view model for each POST action. So if this action requires an id
I include it as part of this specific view model.
精彩评论