开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜