tags:

views:

348

answers:

1

I am an ASP.Net MVC noob.

I cannot get checkboxes to render correctly i.e. checked/unchecked.

This is a snippet of my view:

<input id="<%= item.ReportName + "|" + "email" %>" type="checkbox" checked="<% if     (item.Email == true)  { %>true<% } else {  %>false<% } %>" onclick="ajaxfunction(this)" />

This is the source view from IE:

<input id="TestRep02|showinhomelist" type="checkbox" onclick="ajaxfunction(this)" />

Notice that there is no checked attribute in the html source.

Any ideas?

+1  A: 

it should be:

<input id="<%= item.ReportName + "|" + "email" %>" 
    type="checkbox" <% if (item.Email == true)  { %>checked="yes"<% } %>"
    onclick="ajaxfunction(this)" />

Note: The checked attributes accepts "yes" and "no".. not true or false..

datacop
wow, thanks for the lightening response!! works as expected now.
yuben
I think checked="checked" is the proper attribute name/value to use. See: http://reference.sitepoint.com/html/input/checked
GuyIncognito