JonathanLaker
JonathanLaker

Reputation: 303

How do I create a hidden field in MVC3?

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

Answers (4)

Aidan
Aidan

Reputation: 5536

This works for me:

@Html.EditorFor(m => m.RowKey, new { htmlAttributes = new { @style="display: none" } })

Upvotes: 2

Major Productions
Major Productions

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

Robban
Robban

Reputation: 6802

Could you use the hiddenfor helper, like so:

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

Upvotes: 1

moi_meme
moi_meme

Reputation: 9318

@Html.HiddenFor(model => model.RowKey)

see What does Html.HiddenFor do? for an example

Upvotes: 52

Related Questions