8,497
社区成员
发帖
与我相关
我的任务
分享
public class BookViewModel
{
[Display(Name = "书籍名称")]
public string BookName { get; set; }
[Display(Name = "分类")]
public string CategoryName { get; set; }
}
public class indexModel : PageModel
{
private readonly test.Models.myConn _context;
public indexModel(test.Models.myConn context)
{
_context = context;
}
public List<BookViewModel> GetBookList() {
var books = (from m in _context.Book
join n in _context.MD_Category on m.Category equals n.ID
select new BookViewModel
{
BookName = m.Name,
CategoryName = n.C_Name
}).ToList();
return books;
}
public void OnGet()
{
GetBookList();
}
<table class="table table-hover">
<tr>
<th>
图书名称
</th>
<th>
分类
</th>
</tr>
@foreach (var item in Model.GetBookList())
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.BookName)
</td>
<td align="right">
@Html.DisplayFor(modelItem => item.CategoryName)
</td>
</tr>
}
</table>