C# ASP.NET MVC Basics Modeling and Presenting Data Improving Our View Layout

Elizabeth Hahn
Elizabeth Hahn
16,617 Points

Why does @Model.Favorite render as false the first time it is ran? I mean, is false the default?

Also, once the code is changed to @(Model.favorite ? "yes" : "no") it renders to "no", which I get because because before it rendered to "false" before. But the new layout code from our "designer" is suppose to be "yes" So what exactly is setting this to false the first run and no the second time, and why does it not expressed properly what the designers want? Here is the markup from the designer: <h5><label>Favorite:</label> Yes</h5>

2 Answers

Steven Parker
Steven Parker
173,644 Points

The field's value is false, and the new code converts it to the word "No". This seems exactly as it should be to me.

So why do you say that it 'is suppose to be "yes"'?

Elizabeth Hahn
Elizabeth Hahn
16,617 Points

Because the mark up from the "designers" in the teachers notes has this: <h5><label>Favorite:</label> Yes</h>. I took this to mean that the comic book is indeed a favorite.

Steven Parker
Steven Parker
173,644 Points

Good point, but the fault would be in the data, not the code. In fact, I don't see where a "Favorite" property was added to issue 700 at all. Perhaps a missing property just reads as "false" instead of causing an error.

In any case, you might want to make a bug report to the Support staff.