Asp.Net Core and forests

Generating auto forest on an Asp.Net Razor Page is compatible with bool data types?

I ask for this because I am following this guide: https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model . And at some point, after creating the POCO class, configure dbContext and migrations, I ran this command to automatically create the scaffold

dotnet aspnet-codegenerator razorpage -m Movie -dc MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries

This is beautiful, but just works if my POCO class is not of type bool.

POCO class example:

using System;

namespace RazorPagesMovie.Models
{
    public class Movie
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public DateTime ReleaseDate { get; set; }
        public string Genre { get; set; }
        public bool Active { get; set; }
    }
}

With this implementation, I will get this error when I try to create a movie:

'CreateModel' "Active", "Active", "CreateModel" ( using ?)

?

, , SQLite ...

CreateModel:

using System;    
using System.Collections.Generic;    
using System.Linq;    
using System.Threading.Tasks;    
using Microsoft.AspNetCore.Mvc;    
using Microsoft.AspNetCore.Mvc.RazorPages;    
using Microsoft.AspNetCore.Mvc.Rendering;    
using RazorPagesMovie.Models;

namespace RazorPagesMovie.Pages.Movies    
{    
    public class CreateModel : PageModel    
    {    
        private readonly RazorPagesMovie.Models.MovieContext _context;    

        public CreateModel(RazorPagesMovie.Models.MovieContext context)    
        {    
            _context = context;    
        }        

        public IActionResult OnGet()    
        {    
            Movie = new Movie    
            {    
                Title = "The Good, the bad, and the ugly",    
                Genre = "Western",    
                Price = 1.19M,    
                ReleaseDate = DateTime.Now,    
                Active = true    
            };    
            return Page();    
        }        

        [BindProperty]    
        public Movie Movie { get; set; }    

        public async Task<IActionResult> OnPostAsync()    
        {    
            if (!ModelState.IsValid)    
            {    
                return Page();    
            }    

            _context.Movie.Add(Movie);    
            await _context.SaveChangesAsync();    

            return RedirectToPage("./Index");    
        }    
    }    
}
+4
1

:

@Html.DisplayNameFor(model => model.Active))

Create.cshtml, , model CreateModel, Movie. :

@Html.DisplayNameFor(model => model.Movie.Active))
+6

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


All Articles