1

I have an html helper checkbox on a view in an MVC3 project:

<%
            var temp = Model.NonResident;
            if (Model.NonResident)
               Html.CheckBox("IsNonResident", true);
           else
               Html.CheckBox("IsNonResident", false);
        %>

The model field 'NonResident does have a value of true. I assigned the value to 'temp' and stepped through it. When I debug, the codee does hit the Html.CheckBox("IsNonResident", true) segment but it doesn't render.

I've checked 'View Source' and the control is not there. If I remove the 'if' statement, it does render if I use:

<%=Html.CheckBox("IsNonResident", true)%>

It must be something simple but I can't see it. Can anyone help?

1 Answer 1

1

The difference is the equals sign in <%=Html.CheckBox("IsNonResident", true)%>. That outputs the result. With your if block, you are ignoring the result, so the output never makes it to the http response. One solution is to inline it like this:

<%=Html.CheckBox("IsNonResident", Model.NonResident)%>
Sign up to request clarification or add additional context in comments.

Comments

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.