Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Closed Unassigned: Razor V2 & V3-beta2 : Issue with parsing bool value in HTML tag attribute [1159]

$
0
0
From Razor V2 onwards, I have noticed issue while parsing bool value with HTML tag attribute. Issue reproduced only when we are parsing bool value as HTML tag attribute. Please have a look at below code snippet and output i.e. rendered HTML.

__Code Snippet__
@{
bool trueVal = true;
bool falseVal = false;
}
@trueVal | @falseVal | <input type="text" value="@trueVal" /> | <input type="text" value="@falseVal" />

__Razor V1 Output__
True | False | <input type="text" value="True" /> | <input type="text" value="False" />

__Razor V2 & V3-beta2 Output__
True | False | <input type="text" value="value" /> | <input type="text" />
In above V2 & V3-beta2 output we can see that it is rendering __value="value" for bool True, while for bool False it is not rendering value attribute at all__ Ideally it should be value="True" and value="False" respectively.

__UPDATE__
Ironically it is __working fine for data-*** attribute__ in Razor V2 & V3-beta2 as well! But I found that this is due to conditional attribute introduced in Razor V2. And also found that similar issue is closed earlier as will not fix. [https://aspnetwebstack.codeplex.com/workitem/474](https://aspnetwebstack.codeplex.com/workitem/474)
Comments: Hi Nandip, This was a deliberate behavior change in Razor to allow supporting conditional attributes. The reason that data-*** are not affected is that Razor deliberately ignores those for conditional attributes. We recommend calling .ToString() on values to ensure that they are explicitly written out as-is. Thanks, Eilon

Viewing all articles
Browse latest Browse all 7215

Trending Articles