Hi loymed,
The problem you are having is subtle. The postback
Edit
overload won't be able to de-serialise the form data back into
ModifierUser
as binds to items in a list which is a subproperty of
Utilisateurs
itself. Specifically the
new{id=item.IdUser}
won't set
ModifierUSer.IdUser
.
IIRC if you change
using(Html.BeginForm("Edit","Users",new{id=item.IdUser}))
to
using(Html.BeginForm("Edit","Users",new{IdUser=item.IdUser}))
this will populate the value, but I could be mis-remembering what I did (normally I'd check but I'm at work). Additionally, if you are updating this value (and it looks like you are) might be, you are going to have problems distinguishing between the old an new user ids.
There are a few other ways to skin this preserving the old/new id (this same RAZOR as you have currently):
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, )
{
var OriginalUser = (from u in _db.Utilisateurs
where u.IdUser == id
select u).FirstOrDefault();
}
or there is also a forms collection you can use which might be neater, depends on what else you are doing.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(FormsCollection formsCollection)
{
var OriginalUser = (from u in _db.Utilisateurs
where u.IdUser == formsCollection["id"]
select u).FirstOrDefault();
}