Scaffolding Bool values results in incorrect syntax on the Create and Edit models
See original GitHub issueI have found that if scaffolding a class that contains a Bool value then incorrect syntax is generated on the Create and Edit models (this issue also occurred in .Net Core 2.0):
Steps to reproduce:
public class Customer
{
public int CustomerID { get; set; }
...
[Display(Name = "Can Contact?")]
public bool CanBeContacted { get; set; }
...
}
Then scaffold the class and if you try to build the project it will fail with the following error:
'EditModel' does not contain a definition for 'CanBeContacted' and no accessible extension method 'CanBeContacted' accepting a first argument of type 'EditModel' could be found (are you missing a using directive or an assembly reference?)
The workaround is to change the line in the Create/Edit model from:
<input asp-for="Customer.CanBeContacted" /> @Html.DisplayNameFor(model => model.CanBeContacted)
To:
<input asp-for="Customer.CanBeContacted" /> @Html.DisplayNameFor(model => model.Customer.CanBeContacted)
After this the project builds successfully.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Cannot Scaffold (EF, Core 2.1) model that contains a 'bool ...
For some reason, bool values are NOT being properly referenced by scaffolding. Probably should be a bug for future releases of EF/Core. Much ......
Read more >Incorrect Syntax near ',' using scaffolding
I created the Task Status and Task Status Detail screens with scaffolding ... a syntax error when viewing the status detail view as...
Read more >Model validation in ASP.NET Core MVC and Razor Pages
Model validation occurs after model binding and reports errors where ... resulting in an error message such as The value '' is invalid...
Read more >Calling Stored Procedures with the Entity Framework in . ...
You're going to learn how to retrieve data from a stored procedure, how to pass parameters, return a scalar value, modify data, and...
Read more >Breaking changes in EF Core 6.0
Complete list of breaking changes introduced in Entity Framework Core 6.0.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s not fixed though in the latest version from what I can tell. Looking at #709 it looks like it may have only been fixed in 2.0 with the fix not ported forward to 2.1? Are there plans to fix in 2.1 as well? It also adds an extra closing bracket which just ends up appearing as text on the page.
I do hit it every time I add a bool value and can replicate every time. Visual Studio is fully up to date.
I installed .Net Core 2.2 last night and see the same issue with bool properties in the model.