2017-09-21 19 views
2

Asp.Net Razor Pageへの自動足場の生成はboolデータ型と互換性がありますか?Asp.Net Core and Scaffold

私はこのチュートリアルに従うので、尋ねます:https://docs.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/model。そして時点で、後dbContextおよび移行を設定し、POCOクラスを作成し、私は自動に、このコマンドを実行した

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

その美しい足場を生成するが、私のPOCOクラスはbool型をしていない場合だけで作業します。

例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");  
     }  
    }  
} 
+0

CreateModelクラスの外観はどうですか?ここでMovieクラスを追加しました。 –

+0

@AndreiNeaguこの投稿をCreateModelクラスで更新しました。 – Rafael

+0

この例は、次のサイトからダウンロードできます:https://github.com/aspnet/Docs/blob/master/aspnetcore/tutorials/razor-pages/razor-pages-start/sample/RazorPagesMovie /、DbContextをSQLiteに変更し、POCOの1つのプロパティをboolに変更する必要があります – Rafael

答えて

4

問題は、この行を次のとおりです。

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

これが使用されるCreate.cshtmlでは、modelMovieではなくCreateModelを指します。代わりに、必要があります:

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

足場の手順が改善される可能性はありますか? 、boolプロパティ、ムービー部分? – Rafael

+0

うわこ足場にバグがあります。 – empty