剃刀条件属性不起作用 [英] Razor conditional attribute not working

查看:85
本文介绍了剃刀条件属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在标签中,我想有条件地输出样式属性,例如:<li style="@styleVar" >...</li> 当styleVar为null时,不应由razor编写(只是Razor 2中假定的标准功能),但是由于某些奇怪的原因,它会输出为<li style="">...</li>,而我希望使用<li>...</li>.

In a tag I want to conditionally output the style attribute, e.g.: <li style="@styleVar" >...</li> When styleVar is null it should not be written by razor (just the supposed standard functionality in Razor 2), but for some strange reason it is outputted as <li style="">...</li>, while I expect <li>...</li>.

这是局部视图.在正常情况下,它正在工作. 那么这是局部视图中的错误吗?

This is in a partial view. In a normal view it is working. So is this a bug in partial views?

有人有同样的经历吗?

推荐答案

在部分视图和自定义html属性(例如data-test ="@ test")中,这似乎不起作用.这不会被忽略,而是仍然放入data-test =".因此,MVC团队必须尽快修复此问题.

This does not seem to work in partial views and for custom html attributes such as data-test="@test". This is not omitted, instead it still puts in the data-test="". So the MVC team has to fix this asap.

这篇关于剃刀条件属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆