开发者

ASP.NET MVC: Optionally render element attribute

开发者 https://www.devze.com 2022-12-23 03:36 出处:网络
I know there is some syntax with ? to optionally render attribute. But I can\'t find it now that I need it ...

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

0

精彩评论

暂无评论...
验证码 换一张
取 消