We recently upgraded an existing .NET 4 MVC 3 project to .NET 4.5 and MVC 4.
Where we had this sort of thing in a view:
@Model.MyBool
<input type="hidden" name="foo" value="@Model.MyBool" />
that used to render as:
True
<input type="hidden" name="foo" value="True" />
or:
False
<input type="hidden" name="foo" value="False" />
But now it renders as:
True
<input type="hidden" name="foo" value="value" />
or:
False
<input type="hidden" name="foo" />
That is, where a boolean property is rendered in the view as the value of a hidden input's value attribute, it doesn't render as True
or False
(as it does elsewhere), but rather renders as value
, or misses the attribute altogether.
Two questions:
WTF?
Razor 2 conditional attributes
Is there a nice easy way I can fix the multitude of places that this has broken my application?
None I can think of (that's why you should have used @Html.Hidden("foo", Model.MyBool)
). My best guess would be using something like Resharper's Structured Replace.
looks like this is working:
<input type="hidden" name="foo" value="@Model.MyBool.ToString()" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With