문제

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