ASP.NET MVC: Optionally render element attribute
I know there is some syntax with ? to optionally render attribute. But I can't find it now that I need it ...
Something like:
< input checked=<%? model.IsActivated % > ...
Thanks.
EDIT: Since it seems that nobody knows... perhaps it was some different view engine. Than开发者_JAVA技巧ks for answers any way :)
<input checked="<%= model.IsActivated ? "checked" : string.empty % >"...
But the presense of the "checked" attribute might cause it to be checked, I can't remember. But if that's the case then you'll want
<input <%= model.IsActivated ? "checked=\"checked\"" : string.Empty %> ...
EDIT: btw its called the ternary(? or conditional) operator
精彩评论