In my Controller MVC, I have an Action to show my Model (generic model with 3 fields [Code], [Libelle] and [IsActif]).
[AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
[ActionName("AfficheDetailMotifRejet")]
[AuthorizeRoleFilter(Roles = TypeRoles.Roles.ADMINISTRATEUR_NATIONAL)]
public ActionResult AfficheDetailMotifRejet([DefaultValue(Int64.MinValue)] Int64 id)
{
DetailGeneric dg = new DetailGeneric { Id = id };
if (id > 0)
{
MotifRejet s = _srvMotifRejet.Charger(id);
Mapper.CreateMap<MotifRejet, DetailGeneric>();
dg = Mapper.Map<MotifRejet, DetailGeneric>(s);
}
return View("GererMotifRejet", dg);
}
If I send Int64.MinValue as Id, then my Model is showed empty, ready to be inserted. But when I show to Edit with an existant Id, I need to made the field [Code] in ReadOnly mode.
What is the best solution ?
I think about to add [ReadOnly(true)] attribute in dg.Code, but how to made this ?
However, I can made this with a javascript, but there is a risk, if user don't have javascript activated.
Thanks for your helping.