Вопрос

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 %>" />
Это было полезно?

Решение

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"]) %>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top