Set a hardcoded value in a HiddenFor within a for-loop
问题 When there is only one person to select I still need to assign the hardcoded value 'TRUE' to the People[i].IsSelected property to satisfy my validation. How can I do that? @if (hasMoreThanOnePerson) { <td> @Html.CheckBoxFor(m => m.People[i].IsSelected) </td> } else { @Html.HiddenFor(m => m.People[i].IsSelected, true) // Set TRUE always to hidden field within for loop with indexer } 回答1: Use htmlAttributes to set value property of Hidden Field using this overload or this overload: @Html