Question

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 %>" />
Was it helpful?

Solution

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"]) %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top