sharparchitecture/Sharp-Architecture — Issue #38: SharpModelBinder feature request
Author: vonbv
Created: 2012-02-14 10:10:08+00:00
State: open

I am using the same View for my create and edit actions. This gives me
a tiny issue in that the entity is set to null on create action. And
this is because I put a hidden field for ID on the form. So I have
something like:

@Html.HiddenFor(m=>m.Id)

I understand that that won't work for a create since the
SharpModelBinder queries for the entity. And in our case there's no
record with an ID of zero in the database. So I was thinking if it's
good to have a checking that if the ID is zero (for int) or empty for
(GUID) SharpModelBinder will just return a new entity. In this manner
we can reuse a single view for both create and edit and doesn't have
to write a logic not to write the ID as a hidden field.

I am not sure how much value this puts in S#arp especially that some
people starts an ID with a zero. And also if the requested change
breaks a best practice implemented in S#arp.

Additionally, if my approach on the UI doesn't make sense, please let
me know if there is a better way of doing it.