Questions tagged [html.hiddenfor]
38 questions
136
votes
4 answers
ASP.Net MVC Html.HiddenFor with wrong value
I'm using MVC 3 in my project, and I'm seeing a very strange behavior.
I'm trying to create a hidden field for a particular value on my Model, the problem is that for some reason the value set on the field does not correspond to the value in the…

willvv
- 8,439
- 16
- 66
- 101
110
votes
4 answers
What does Html.HiddenFor do?
Although I have read the documentation on Html.HiddenFor, I've not grasped what is it used for...
Could somebody explain its uses and give a short example?
Where should those helpers go in the code?

JPCF
- 2,232
- 5
- 28
- 50
75
votes
6 answers
What is the difference between Html.Hidden and Html.HiddenFor
I can find a good definition for Html.HiddenFor on MSDN but the only thing I can find on Html.Hidden is related to problems it has.
Can someone give me a good definition and an example.

Joe Pitz
- 2,434
- 3
- 25
- 30
61
votes
7 answers
HTML.HiddenFor value set
@Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", @value = '@Model.title'})
it doesen't work! how to set the value?

arnoldrob
- 813
- 3
- 9
- 15
28
votes
6 answers
Html.HiddenFor value property not getting set
I could have used
@Html.HiddenFor(x=> ViewData["crn"])
but, I get,
To somehow circumvent that issue(id=ViewData_crn_ and name=ViewData[crn]), I tried doing the following,…

Sekhar
- 5,614
- 9
- 38
- 44
24
votes
6 answers
Pass an entire model on form submission
I understand that I can use @Html.HiddenFor(m => m.parameter) and when the form is submitted, that parameter will be passed to the controller. My model has many properties.
Is there a shorter way of passing the entire model at once to the…

jpo
- 3,959
- 20
- 59
- 102
17
votes
4 answers
Boolean with html helper Hidden and HiddenFor
What's up with this? The viewmodel variable is a bool with value true.
<%= Html.HiddenFor(m => m.TheBool) %>
<%= Html.Hidden("IsTimeExpanded",Model.TheBool) %>
Results…

Martin
- 2,956
- 7
- 30
- 59
8
votes
3 answers
Set the value of a Html.Hiddenfor
I have a form, to submit a bid.
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "Login" }))
{
@Html.ValidationSummary(true, "Gelieve alle velden in te vullen.")
@Html.LabelFor(m => m.Bid)
@Html.TextBoxFor(m =>…
@Html.TextBoxFor(m =>…

Lonefish
- 647
- 2
- 11
- 32
8
votes
1 answer
difference between Html.HiddenFor & HiddenInput attribute
HiddenFor description is:
Returns an HTML hidden input element for each property in the object that is represented by the specified expression.
I read that it is useful for fields in your Model/ViewModel that you need to persist on the page and have…

Nizar Blond
- 1,826
- 5
- 20
- 42
7
votes
1 answer
Why does the Html.HiddenFor generate the data-val- attributes
The standard output of @Html.HiddenFor(model => model.Id) is
Is there a need for the…

Rudi
- 3,124
- 26
- 35
6
votes
3 answers
Pass a ViewBag instance to a HiddenFor field in Razor
Using ASP.NET MVC and Razor, I'm trying to pass a ViewBag item from the controller to a HiddenFor field (using Razor). I get the following message: Extension methods cannot by dynamically dispatched.
@Html.HiddenFor(m=>m.PortfolioId,…

crowsfeet
- 203
- 1
- 4
- 16
5
votes
1 answer
The model's Hidden bool field remains False after it was set True in the controller
I have this property in my ViewModel class:
public bool AreSimilarEntitiesChecked { get; set; }
In my controller I set its value 'true' and return the View with the model:
model.AreSimilarEntitiesChecked = true;
return…

kmarton
- 53
- 1
- 3
4
votes
2 answers
How can i set Default value for HiddenFieldFor In Asp.Net MVC
i am using HiddenFor with model binding which is binding value to it.
i want to reset the binded value to zero.How can i do it?
i tried this but it is not working...
<% foreach (var item in Model ) { %>
<%: Html.HiddenFor(model => model.ID,new {…

coolguy97
- 565
- 1
- 7
- 12
3
votes
1 answer
Model Binder & Hidden fields
I have a simplified test scenario useful for asking this question: A Product can have many Components, a Component can belong to many Products. EF generated the classes, I've slimmed them as follows:
public partial class Product
{
public int Id…

ekkis
- 9,804
- 13
- 55
- 105
3
votes
2 answers
hiddenFor helper is pulling id from action parameter, not the viewModel
I've stumbled upon a really weird situation with ASP.Net MVC, passing an "id" as an action parameter and an "id" hidden form element. I have an action that has an "id" parameter. This id value represents a project. I have a controller action…

Tom Schreck
- 5,177
- 12
- 68
- 122