Reputation: 303
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?
Upvotes: 28
Views: 50541
Reputation: 5536
This works for me:
@Html.EditorFor(m => m.RowKey, new { htmlAttributes = new { @style="display: none" } })
Upvotes: 2
Reputation: 6042
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
}
Upvotes: 44
Reputation: 6802
Could you use the hiddenfor helper, like so:
@Html.HiddenFor(m => m.RowKey)
Upvotes: 1
Reputation: 9318
@Html.HiddenFor(model => model.RowKey)
see What does Html.HiddenFor do? for an example
Upvotes: 52