Assign ViewBag value to input checkbox?
14,622
I recommend using this, assuming you are using Razor:
@Html.CheckBox("chkSolicitation", (bool)ViewBag.Solicitation)
If you are not using Razor, use this:
<%: Html.CheckBox("chkSolicitation", (bool)ViewData["Solicitation"]) %>
Author by
James123
Updated on June 28, 2022Comments
-
James123 almost 2 years
I am trying to assign
ViewBag
value in Boolean to an HTML Input checkbox. It is throwing the following error:Cannot resolve symbol '<%= ViewBag.Solicitation %>'
<input id="chkSolicitation" type="checkbox" name="chkSolicitation" checked="<%= ViewBag.Solicitation %>" />