Asp.Net Razor Page的自动脚手架的生成与bool数据类型兼容吗?Asp.Net Core和Scaffold
我问了一下,因为我按照这个教程:https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model。而在一个点,之后创建POCO类,配置的DbContext和迁移,我跑这个命令来自动生成支架
dotnet aspnet-codegenerator razorpage -m Movie -dc MovieContext -udl -outDir Pages\Movies --referenceScriptLibraries
其美丽的,只是工作,如果我的POCO类有没有布尔类型。
例POCO类:
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; }
}
}
有了这个实现我去拿,当试图创建一个电影,这个错误:
'CreateModel' does not contain a definition for 'Active' and no extension method 'Active' accepting a first argument of type 'CreateModel' could be found (are you missing a using directive or an assembly reference?)
任何想法?
也许是我的事实,我使用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");
}
}
}
CreateModel类是怎么样的?你在这里添加了Movie类。 –
@AndreiNeagu我更新了CreateModel类的帖子.. – Rafael
该示例可以从以下网址下载:https://github.com/aspnet/Docs/blob/master/aspnetcore/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie /,但必须将DbContext更改为SQLite,并将POCO的一个属性更改为bool – Rafael