Why mvc Html.HiddenFor does not render my field?

Viewed 16161

I'm trying to do this simple thing

<%= Html.HiddenFor(model => model.Id)%>

the model is

[HiddenInput(DisplayValue=true)]
public int Id { get; set; }

but i always get this rendered

<input type="hidden" value="0" name="UserInfo.Id" id="UserInfo_Id">

i've check and the id is NOT 0.. ?!

need some explanation here...

Edit

The problem seem's to be the post thing mentionned below. This is working

<input type="hidden" value="<%= Html.AttributeEncode(Model.Id) %>" id="<%= Html.IdFor(model=>model.Id)%>" name="<%= Html.NameFor(model=>model.Id)%>" />

Thanks to Manaf

4 Answers
Related