سؤال

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