I'm using MVC3. When I make a field with
@Html.EditorFor(model => model.RowKey)
Then the value gets sent back to the controller which is what I need. However I don't want the field to be visible even though I want its value to be returned to the controller.
Is there a way I can make a field hidden with MVC3?
Definition and UsageThe <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted.
The Html. Hidden() method generates a input hidden field element with specified name, value and html attributes.
You pass the model through to the Razor page, which will build HTML appropriate to that model. If you want to have a hidden element which sets true or false depending on whether this is the first view or not you need a bool in your model, and set it to True in the Action if it's in response to a follow up.
@Html.HiddenFor(model => model.RowKey)
see What does Html.HiddenFor do? for an example
If you want to keep Html.EditorFor()
, you could always mark a particular property of your model as hidden:
using System.Web.Mvc.HiddenInput; public class Model { [HiddenInput(DisplayValue = false)] // some property }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With