13
新建Controllers文件夹,在里面添加HomeController控制器
新建Views文件夹,再新建Home文件夹。再新建Index.cshtml的视图页面
注释上节课的代码,否则我们的管道都会被抵消,最后只输出了。appsettings.json文件的内容
注入MVC
添加默认路由,
这样就把整个MVC的middleware添加到我们的应用程序当中
使用IOptions是一个泛型的方法,把我们的Class传进去,
Controller内输出代码
@model OptionsBindSample.Class @{ ViewData["Title"] = "Index"; } <h2>Index</h2> <h4>Class No: @Model.ClassNo</h4> <h4>Class Desc: @Model.ClassDesc</h4> <h3> Students: </h3> <div> @foreach (var student in Model.Students) { <span>Name: @student.Name</span> <span>Age: @student.Age</span> } </div>