Hi guys,
This is quite simple but I learned something new in MVC today, so thought to share with you all.
I was trying to assign a Boolean field to a hidden field using ViewBag in MVC.
- <input type="hidden" id="somehiddenfield" value="@ViewBag.MyBooleanValue" />
- var hiddenVal = $("#somehiddenfield").val();
i.e. You will get the hidden field’s value as “value” when the Boolean value will be true and nothing when Boolean value will be false.
So you might need to change the implementation a little if you explicitly want to read the true and false as hidden field values from JQuery.
- <input type="hidden" id="somehiddenfield " value="@(ViewBag.MyBooleanValue.ToString())" />
Hope this helps someone.

Amresh KumarPosted Feb 5, 2019, 12:07 PM
My @Html.HiddenFor(model => model.Active) generates value as 'False' rather then 'false' which messing up my Modal validation. Any clue to render the value as 'false' ?
Ravi prasadPosted Jul 28, 2015, 6:58 PM
That helps. Thanks mate
Manish Kumar ChoudharyPosted Jan 5, 2015, 9:04 AM
Nice one...