question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scaffolding Bool values results in incorrect syntax on the Create and Edit models

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
robinwilson16commented, Aug 21, 2018

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.

2reactions
timomtacommented, May 2, 2019

I installed .Net Core 2.2 last night and see the same issue with bool properties in the model.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found