Hiddenfield in aspx to cshtml

Asked

Viewed 36 times

0

I have a doubt about hiddenfield in aspx we use the following command:

<asp:HiddenField ID="HiddenField1" runat="server" /> 

And for cshtml it is possible?

1 answer

0


In Razor you can use the @Html.HiddenFor() which will be very useful if you are using a Model

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

Otherwise, as in the example presented in the question... it does not make much sense to create this component on the server side if it is to represent a model object, but it can be done, too:

@Html.Hidden("HiddenField1","valorQuandoSelecionado")

In that case it would be better to write pure html anyway...

<input type="checkbox" name="HiddenField1" value="valorQuandoSelecionado" />
  • It worked! Thanks! @Html.Hiddenfor(m => m.Property)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.