I have my form with my checkbox inputs, and user can edit that. I can save these values in database good, but I don't know how to refill the form, so user can edit it.
This is my ViewBag var:
ViewBag.NewFriends = preferences.NewFriends;// this value is a boolean, false
I try to pre-set values like this:
@using (Html.BeginForm("SavePreferences", "Conta"))
{
@Html.HiddenFor(model => model.ID)
@Html.CheckBox("newFriends", new { @checked = @ViewBag.NewFriends })
@Html.Label("newFriends", "Solicitações de Amigo de Alma")
<p><input type="submit" value="Send" /></p>
}
As HTML checkbox has the value checked="checked", and not true or false, it doesn't work. @Html.CheckBox has the first parameter as input name, and second a boolean checked(true or false).
My question is how can I easily set up this value? I tried:
@Html.CheckBox("newFriends", ViewBag.NewFriends) // where ViewBag.NewFriends = false
But it doesn't work at all...
Any idea?