1

Is it possible to do something like this?

<input type="checkbox" ('@ViewData["Mailing"]'!= null ? @checked) />

1 Answer 1

5

Yes, it is possible:

<input type="checkbox" @(ViewData["Mailing"] != null ? @checked : "") />

but it is not something that you should want to do especially when you have strongly typed helpers at your disposal that already take care for this:

@Html.CheckBoxFor(x => x.Mailing)

Shorter, strongly typed, no ViewData, no spaghetti.

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.