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