开发者

Entity ID as input model field vs action parameter?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜