3

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 %>" />
3
  • can you use checked="@ViewBag.Solicitation" /> Commented Jul 10, 2013 at 19:19
  • No hes not using razor ..that would read @ViewBag.Solicitation :) Commented Jul 10, 2013 at 19:19
  • ViewBag.Solicitation should be assigned to the value="", checked just says if its checked or not, has nothing to do with the actual value assigned. btw checked is not checked="true/false", if checked exists then it's checked ..checked="false" will check the box ! Commented Jul 10, 2013 at 19:21

1 Answer 1

9

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"]) %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.