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 Answer 1

1

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..

Sign up to request clarification or add additional context in comments.

2 Comments

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

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.