MovieViewModel 2 { MovieId { get; set; } MovieName { get; set; } MovieTypeId { get; set; } MovieTypeName { get; set; } DateTime MovieAddTime { get; set; } 12 }
MovieViewModel.cs
MovieListViewModel 2 { 3 public IEnumerable<MovieViewModel> Movies { get; set; } 4 }
MovieListViewModel.cs十、现在就该写写类似mvc控制器的东西了,在Modules文件夹下建立MovieModule.cs
把数据提取出来
MovieModule : NancyModule 2 { ) 4 { ] = _ => ShowMovieIndexPage(); 6 } _sqlconnection = ; SqlConnection OpenConnection() 12 { 13 SqlConnection connection = new SqlConnection(_sqlconnection); 14 connection.Open(); 15 return connection; 16 } ShowMovieIndexPage() 19 { 20 using (IDbConnection conn = OpenConnection()) 21 { ; 23 MovieListViewModel viewModel = new MovieListViewModel 24 { 25 Movies = conn.Query<MovieViewModel>(getAllMoviesStoredProcedure, 26 null, null, true, null, CommandType.StoredProcedure) 27 }; , viewModel]; 29 } 30 } 31 }
MovieModule.cs然后就去编写视图
在Views下面新建一个Movie文件夹,用于存放相关视图
1 @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<MovieDemo.ViewModels.MovieListViewModel> 2 @{ ; ; 5 } >添加</a> 7 <div> > 9 <tr> 10 <th> 11 # 12 </th> 13 <th> 14 电影名称 15 </th> 16 <th> 17 电影类型 18 </th> 19 <th> 20 添加时间 21 </th> 22 <th></th> 23 </tr> 24 @foreach (var item in Model.Movies) 25 { 26 <tr> 27 <td> 28 @item.MovieId 29 </td> 30 <td> 31 @item.MovieName 32 </td> 33 <td> 34 @item.MovieTypeName 35 </td> 36 <td> 37 @item.MovieAddTime 38 </td> 39 <td> >修改</a> href=>删除</a> 42 </td> 43 </tr> 44 } 45 </table> 46 </div>
Index.cshtmlF5跑一下
OK!
然后就是修改某条数据,
在MovieModule.cs 的构造函数中添加