How to work with MVC4, breaking changes in the way it displays bools in a view

We recently upgraded an existing .NET 4 MVC 3 project to .NET 4.5 and MVC 4.

If we had such things in view:

@Model.MyBool <input type="hidden" name="foo" value="@Model.MyBool" /> 

which is used to display as:

 True <input type="hidden" name="foo" value="True" /> 

or

 False <input type="hidden" name="foo" value="False" /> 

But now it displays as:

 True <input type="hidden" name="foo" value="value" /> 

or

 False <input type="hidden" name="foo" /> 

That is, when a logical property is displayed in the view as the attribute value of a hidden input value, it does not appear as True or False (as it happens elsewhere), but rather displays as value , or does not skip the attribute at all.

Two questions:

  • WTF?
  • Is there a good easy way I can fix a lot of places that have broken my application? This is a great application, and I do not like to trawl every point of view to try to determine wherever I put the bool in the input field.
+6
source share
2 answers

WTF?

Razor 2 conditional attributes

Is there a good easy way that I can fix many places that have broken my application?

Not. I can think (why you should use @Html.Hidden("foo", Model.MyBool) ). My best guess would be to use something like Resharper Structured Replace.

+3
source

looks like that:

 <input type="hidden" name="foo" value="@Model.MyBool.ToString()" /> 
+2
source

Source: https://habr.com/ru/post/924305/


All Articles