Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a hidden field in MVC3?

Tags:

asp.net-mvc

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?

like image 811
JonathanLaker Avatar asked Apr 20 '11 14:04

JonathanLaker


People also ask

How do you input a hidden field?

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.

How do you create a hidden field in Cshtml?

The Html. Hidden() method generates a input hidden field element with specified name, value and html attributes.

How do you create a hidden field in MVC Razor?

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.


2 Answers

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

see What does Html.HiddenFor do? for an example

like image 86
moi_meme Avatar answered Sep 23 '22 04:09

moi_meme


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 } 
like image 22
Major Productions Avatar answered Sep 23 '22 04:09

Major Productions