dotnet / Scaffolding

Code generators to speed up development.
MIT License
640 stars 228 forks source link

Scaffolding Bool Values Results in Additional Closing Bracket #1212

Open robinwilson16 opened 4 years ago

robinwilson16 commented 4 years ago

This has been a bug since at least .NET Core 2.0 (not tried earlier versions) and I logged it in Aug 2018 where if you scaffold bool properties they add an additional closing bracket to the output on the Create model.

e.g. it produces this:

<div class="form-group">
                <div class="checkbox">
                    <label>
                        <input asp-for="Emoji.IsEnabled" /> @Html.DisplayNameFor(model => model.Emoji.IsEnabled)**)**
                    </label>
                </div>
            </div>

With an extra closing bracket after model.Emoji.IsEnabled))

It should appear without the additional closing bracket which just shows on the page like this: Annotation 2019-12-31 193709

Please can this minor issue be fixed? Bool values did used to cause invalid syntax that would not compile unless generated code was fixed by hand so it is better but still not 100% fixed. This is my original issue from 2018: aspnet/Scaffolding#855

deepchoudhery commented 4 years ago

Is this 2.1/2.2 project or 3.1?

robinwilson16 commented 4 years ago

@deepchoudhery It happens on all of them but is still there on 3.1 which I just tested. Earlier versions also generated invalid syntax that stopped the project compiling and this bit is fixed but the extra bracket persists to the latest 3.1 version.

deepchoudhery commented 4 years ago

Hi, This is concerns razor pages right? We had a fix put for bootstrap 4 templates but missed bootstrap 3 templates. We're looking into patching it soon.

robinwilson16 commented 4 years ago

@deepchoudhery Yes sorry this is on a Razor page and is when you scaffold the pages selecting the CRUD option where it generates the list, view, add, edit and delete pages (a very helpful feature for quick development) but I am using Bootstrap 4 and have been even since before it was supported in Visual Studio (by fixing up the design afterwards) so I can confirm this bug is with the default .NET Core Web Application and when scaffolding a full set of pages against a data model using the default Bootstrap 4 templates. The bug has existed since 2018 and persists to this day but is only a very minor issue and even with a lot of checkboxes just takes a quick find and replace - I'm just not sure why it has never been fixed.

deepchoudhery commented 4 years ago

Hmmm I definitely cannot reproduce this using the CodeGeneration 3.1.0 package(this nuget pkg contains the fix). Could you confirm you are using this package? It reproduces in 2.0, 2.1, and 2.2. 3.0 is out of support but is fixed for 3.1. Let me know, thanks.

robinwilson16 commented 4 years ago

@deepchoudhery sorry for the delay in getting back about this. This is what the project currently says and I have just created a new project, created the model and scaffolded the page.

Looking in the .csproj file this is what it says:

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" />

Now it generates bool values as standard input boxes rather than checkboxes so this is now worse than it was before.

Here is an example:

Model contains this:

namespace OnlineApplications.Models
{
    public class Application
    {
        public int ApplicationID { get; set; }
        public bool? PreferLetter { get; set; }
        ...
    }
}

This scaffolds as:

<div class="form-group">
    <label asp-for="Application.PreferLetter" class="control-label"></label>
    <input asp-for="Application.PreferLetter" class="form-control" />
    <span asp-validation-for="Application.PreferLetter" class="text-danger"></span>
</div>